For any given date, how would you find the week ending date of the last completed week, if your week runs from Sunday to Saturday?
public static DateTime EndOfWeek(DateTime dateTime)
{
DateTime start = StartOfWeek(dateTime);
return start.AddDays(6);
}
public static DateTime StartOfWeek(DateTime dateTime)
{
int days = dateTime.DayOfWeek - DayOfWeek.Monday;
if (days < 0)
days += 7;
return dateTime.AddDays(-1 * days).Date;
}
To find the end of the previous week, just call:
DateTime endPrevWeek = StartOfWeek(DateTime.Today).AddDays(-1);