CSharp examples for System:DateTime Month
Last Day Of Month
using System.Text; using System.Linq; using System.Collections.Generic; using System;/*www . ja v a 2 s .c o m*/ public class Main{ public static DateTime LastDayOfMonth(this DateTime dt, DayOfWeek dow) { return dt.LastDayOfMonth().PreviousDay(dow, true); } public static DateTime LastDayOfMonth(this DateTime dt) { return dt.FirstDayOfMonth().AddMonths(1).AddDays(-1); } public static DateTime PreviousDay(this DateTime dt, DayOfWeek dow, bool includeThis) { int diff = dt.DayOfWeek - dow; if ((includeThis && diff < 0) || (!includeThis && diff <= 0)) diff += 7; return dt.Date.AddDays(-diff); } public static DateTime PreviousDay(this DateTime dt, DayOfWeek dow) { return dt.PreviousDay(dow, false); } public static DateTime PreviousDay(this DateTime dt) { return dt.Date.AddDays(-1); } public static DateTime FirstDayOfMonth(this DateTime dt, DayOfWeek dow) { return dt.FirstDayOfMonth().NextDay(dow, true); } public static DateTime FirstDayOfMonth(this DateTime dt) { return new DateTime(dt.Year, dt.Month, 1); } }