ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ThisWeekMonday

Returns a DateTime representing the Monday of the current week. Depends on System.Globalization

Source

public static DateTime ThisWeekMonday(this DateTime dt)
{
   var today = DateTime.Now;
   return new GregorianCalendar().AddDays(today, -((int)today.DayOfWeek) + 1);
}

Example

var monday = DateTime.Now.ThisWeekMonday();

Author: Charles Cherry

Submitted on: 31 aug. 2010

Language: C#

Type: System.DateTime

Views: 5938