Week date

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

If I have week number for example: 24
how can I get start(monday) and end(sunday) date?

Thank you,
Simon
 
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
 
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
 
Back
Top