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?
If you want to specify which day is the end of week, and you don't want to worry about what day the system has defined as the default start of the week, use this method:
private static DateTime GetPreviousSpecifiedDayOfWeek(DateTime dt, DayOfWeek day)
{
if (dt.DayOfWeek == day)
{
return dt;
}
while (dt.DayOfWeek != day)
{
dt = dt.AddDays(-1);
}
return dt;
}