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

IsLastDayOfTheMonth

Returns whether the given date is the last day of the month.

Source

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

Example

var isLastDay = DateTime.Now.IsLastDayOfTheMonth()

Author: Tom De Wilde

Submitted on: 13 dec 2013

Language: C#

Type: System.DateTime

Views: 5117