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

GetLastDayOfMonth

Gets the last date of the month of the DateTime.

Source

public static DateTime GetLastDayOfMonth(this DateTime dateTime)
{
    return new DateTime(dateTime.Year, dateTime.Month, 1).AddMonths(1).AddDays(-1);
}

Example

DateTime lastDay = DateTime.Now.GetLastDayOfMonth();

Author: Brendan Enrick

Submitted on: 22 jan. 2009

Language: C#

Type: System.DateTime

Views: 9121