Results 1 to 3 of 3

Thread: [RESOLVED] Help with Datetime

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help with Datetime

    Hi guys! Is it posible to get the date (yyy-MM-dd) of a particular day, say today is friday and i want to get the date last monday. Is it posible? how? Thanks!

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

    Re: Help with Datetime

    First of all forget any talk of format. DateTime objects have no format. They are just a date and time value. No date or time calculation needs to, or should, consider format. Format is only a consideration when displaying a DateTime, which means when converting it to a string. You can convert any DateTime value to a stri8ng in any format you want. That's a given, so don't even consider it when talking about date/time calculations.

    You can use the DayOfWeek enumeration. Monday has a numerical value of 1, so you can get the numerical value of the current day and and then subtract the difference:
    C# Code:
    1. DateTime mondayThisWeek = DateTime.Today.AddDays(-DateTime.Today.DayOfWeek + 1)
    Just note that if today is Sunday then that calculation will give you tomorrow's date, because Sunday is considered the first day of the week. If you want to use some other rule then you can perform the appropriate translation.
    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
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help with Datetime

    Sorry for that, the
    (yyy-MM-dd)
    was misinterpreted or I just used it in a wrong way, the reason why I put the
    (yyy-MM-dd)
    is to emphasize the date because may be some would think that it is a day e.g Monday, tuesday, etc...My mistake...Anyway, thanks a lot JM!

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