Week date
(Thursday, January 27, 2005)
Found the following interesting discussion in the Newsgroups:
Week date by:simon
| If I have week number for example: 24 how can I get start(monday) and end(sunday) date?
Thank you, Simon
| | | Reply: by:gani
| | | simon,
i'm not sure if there's a built-in funtionality in .net to solve your problem. in case there's none, you can try this one.
Dim dt as new DateTime (DateTime.Now.Year,1,1) Dim week_number as Integer = 1 'change week number Dim days_in_week as Integer = 7 Dim start_date as String Dim end_date as String dt = dt.AddDays(( (week_number-1) * days_in_week) - 1)
While ((dt.DayOfWeek <> DayOfWeek.Monday)) dt = dt.AddDays(-1) End While start_date = dt.ToShortDateString() end_date = dt.AddDays(days_in_week- 1).ToShortDateString()
Console.WriteLine("Start: {0} | End: {1}",start_date, end_date)
HTH
gani http://thedeveloperscorner.com.ph
| | | Reply: by:Jay B. Harlow [MVP - Outlook]
| | | Gani, That's about what I was going to say.
However you don't really need the While loop, you can use:
dt = dt.AddDays(dt.Monday - dt.DayOfWeek)
To get the same effect.
Hope this helps Jay
|

|
0 Comments:
Post a Comment
<< Home