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.

By Tim TrottC# ASP.Net MVC • March 4, 2010
Get Week Commencing Date from DateTime in C#

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.

C#
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;
}

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

My website and its content are free to use without the clutter of adverts, popups, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

New comments for this post are currently closed.