Results 1 to 3 of 3

Thread: Date Logic

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    Date Logic

    I need to make a function, where, when I provide a Date as a parameter, it should return the first day of the week (the date falls.). Pls help me with the logic. I am coding in c#
    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Date Logic

    It depends what day you consider to be the first of the week. The DayOfWeek enumeration considers Sunday to be day 0 and Saturday to be day 6. If that is OK with you then you can use this:
    Code:
    private DateTime GetFirstDayOfWeek(DateTime date)
    {
        return date.AddDays(-(int)dt.DayOfWeek);
    }
    If you consider Monday to be the first day of the week then you'll need to do a bit of extra work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    Re: Date Logic

    Thanks
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width