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

IsLeapYear

Returns whether or not a DateTime is during a leap year.

Source

public static bool IsLeapYear(this DateTime value)
{
    return (System.DateTime.DaysInMonth(value.Year, 2) == 29);
}

Example

if (DateTime.Today.IsLeapYear())
{
    Response.Write("It is a leap year!");
}

Author: Brendan Enrick

Submitted on: 3 jul 2008

Language: C#

Type: System.DateTime

Views: 6751