|
-
Jul 27th, 2007, 03:45 AM
#1
Thread Starter
Fanatic Member
[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!
-
Jul 27th, 2007, 05:38 AM
#2
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:
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.
-
Jul 29th, 2007, 04:52 PM
#3
Thread Starter
Fanatic Member
Re: Help with Datetime
Sorry for that, the was misinterpreted or I just used it in a wrong way, the reason why I put the 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|