CSharp examples for System:DateTime Week
Returns the date of the start of the week for the specified datetime For example, if Monday is considered the start of the week: "2015-05-13" would return "2015-05-11" from http:stackoverflow.coma380641755417
// Copyright by the Spark Development Network using System;//from w ww.ja va2s .c o m public class Main{ /// <summary> /// Returns the date of the start of the week for the specified date/time /// For example, if Monday is considered the start of the week: "2015-05-13" would return "2015-05-11" /// from http://stackoverflow.com/a/38064/1755417 /// </summary> /// <param name="dt">The dt.</param> /// <param name="startOfWeek">The start of week.</param> /// <returns></returns> public static DateTime StartOfWeek( this DateTime dt, DayOfWeek startOfWeek ) { int diff = dt.DayOfWeek - startOfWeek; if ( diff < 0 ) { diff += 7; } return dt.AddDays( -1 * diff ).Date; } }