CSharp examples for System:DateTime Week
Last Day Of Week
using System.Threading.Tasks; using System.Linq; using System.Collections.Generic; using System;// ww w. j av a 2 s. c o m public class Main{ public static DateTime LastDayOfWeek(this DateTime dt) { return dt.FirstDayOfWeek().AddDays(6); } public static DateTime FirstDayOfWeek(this DateTime dt) { var culture = System.Globalization.CultureInfo.CurrentCulture; var diff = dt.DayOfWeek - culture.DateTimeFormat.FirstDayOfWeek; if (diff < 0) diff += 7; return dt.AddDays(-diff).Date; } }