Get Week Commencing Date from DateTime in C#This code will calculate the week commencing date for a given DateTime and return a DateTime containing the date of the start of the week.
The first day of the week is governed by the system CultureInfo. For some regions, the first day of the week is Monday, whilst for others it is Sunday. For example, in the UK (en-GB) culture, the first day will be a Monday, whereas in America (en-US) culture it will be a Sunday.
public static DateTime GetWeekCommencing(DateTime date)
{
CultureInfo info = Thread.CurrentThread.CurrentCulture;
DayOfWeek firstday = info.DateTimeFormat.FirstDayOfWeek;
DayOfWeek today = info.Calendar.GetDayOfWeek(date);
int diff = today - firstday;
DateTime firstDate = date.AddDays(-diff);
return firstDate;
}