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

Get Week Commencing from DateTime in C#

Date manipulation to get the start of the week

Written By on in C#

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

 

Comments

There are no comments for this post. Be the first!

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me