Sample code to get the first day of the week given a date and a DateTimeFormatInfo.
public static DateTime StartOfWeek(DateTime date, DateTimeFormatInfo dateTimeFormat) { Debug.Assert(dateTimeFormat != null, "dateTimeFormat != null"); if (dateTimeFormat == null) { throw new ArgumentNullException("dateTimeFormat"); } DayOfWeek currentDay = date.DayOfWeek; DayOfWeek firstDay = dateTimeFormat.FirstDayOfWeek; int difference = (int)firstDay - (int)currentDay; // we always have to move back, // since we're interested in the first day of the week if (difference > 0) { difference -= 7; } return date.AddDays(difference); }
The attached sourcefile contains the testcases. StartOfCurrentWeek.cs.txt