Get week dates

  • Thread starter Thread starter MFRASER
  • Start date Start date
M

MFRASER

If I have a date how can I find out the beginning of the week and the end of
the week?



System.DateTime StartDate = new DateTime(2003,10,29);

System.DateTime StartWeek = ?

System.DateTime EndWeek = ?
 
The DateTime.DayOfWeek property will give you an enum that ranges from 0
(Sunday) to 6 (Saturday). So you should be able to:

int DaysToStartOfWeek = (int) StartDate.DayOfWeek;

int DaysToEndOfWeek = (int)DayOfWeek.Saturday - (int)StartDate.DayOfWeek;

DateTime StartWeek = Today.Subtract(new TimeSpan(DaysToStartOfWeek,0,0,0));

DateTime EndWeek = Today.Add(new TimeSpan(DaysToEndOfWeek,0,0,0));

You'll have to mess around with it a bit if you wanted the date on Monday
for the start of the week and Sunday for the end of the week (just add one
to DaysToStartOfWeek and DaysToEndOfWeek)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top