Web Design that taps into the haromny and vision of your dreams.

Get Week Commencing from DateTime in C#

By on in Coding

35 words, estimated reading time 1 minutes.

This snippet will calculate the date of the start of the week from a given DateTime and return a DateTime containing the week commencing date.

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;

Last updated on: Wednesday 21st June 2017



Have a question or suggestion? Please leave a comment to start the discussion.


Leave a Reply

Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Your email address will not be published.