Finding Start and End Dates of Previous Week

private void GetDates(ref System.DateTime stDate, ref System.DateTime endDate)
{
double offset = 0;
switch (System.DateTime.Today.DayOfWeek)
{
case DayOfWeek.Monday:
offset = 0;
break;
case DayOfWeek.Tuesday:
offset = -1;
break;
case DayOfWeek.Wednesday:
offset = -2;
break;
case DayOfWeek.Thursday:
offset = -3;
break;
case DayOfWeek.Friday:
offset = -4;
break;
case DayOfWeek.Saturday:
offset = -5;
break;
case DayOfWeek.Sunday:
offset = -6;
break;
}
endDate = System.DateTime.Today.AddDays(offset);
stDate = System.DateTime.Today.AddDays(-7 + offset);
}

courtesy : http://www.knowdotnet.com/articles/getpreviousmonday.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s