Date.IsLeapYear
DateReturns true if the year of the given date is a leap year.
Syntax
Date.IsLeapYear(dateTime as any) as nullable logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A date, datetime, or datetimezone value. |
Return Value
logical — true if the year is a leap year, false otherwise.
Remarks
Date.IsLeapYear returns true if the year component of the input date is a leap year (i.e., divisible by 4, except centuries unless also divisible by 400), and false otherwise. This is equivalent to checking whether Date.DaysInMonth(#date(year, 2, 1)) = 29. If the input is null, the function returns null.
The Gregorian calendar leap year rule: a year is a leap year if it is divisible by 4, except for century years (divisible by 100) which must also be divisible by 400. This is why 2100 is not a leap year despite being divisible by 4.
A practical use for Date.IsLeapYear is adjusting date arithmetic that involves February — for example, when computing annualized rates or building calendar tables that need to account for the extra day. You can also use Date.DaysInMonth on February 1 of the year for the same check, which is sometimes more intuitive.
Examples
Example 1: Flag leap-year orders in the Sales table
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(Sales, 5),
{"OrderID", "OrderDate"}
),
"IsLeapYear", each Date.IsLeapYear([OrderDate]), type logical
)OrderID | OrderDate | IsLeapYear | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | TRUE |
| 2 | 2 | 1/18/2024 | TRUE |
| 3 | 3 | 2/1/2024 | TRUE |
| 4 | 4 | 2/10/2024 | TRUE |
| 5 | 5 | 3/5/2024 | TRUE |
Example 2: Test the leap year rule including century years
#table(
type table [Year = number, IsLeap = logical],
{
{2024, Date.IsLeapYear(#date(2024, 1, 1))},
{2023, Date.IsLeapYear(#date(2023, 1, 1))},
{2100, Date.IsLeapYear(#date(2100, 1, 1))},
{2000, Date.IsLeapYear(#date(2000, 1, 1))}
}
)Year | IsLeap | |
|---|---|---|
| 1 | 2,024 | TRUE |
| 2 | 2,023 | FALSE |
| 3 | 2,100 | FALSE |
| 4 | 2,000 | TRUE |
Example 3: Compute the number of days in the year
#table(
type table [Year = number, DaysInYear = number],
{
{2024, if Date.IsLeapYear(#date(2024, 1, 1)) then 366 else 365},
{2023, if Date.IsLeapYear(#date(2023, 1, 1)) then 366 else 365},
{2100, if Date.IsLeapYear(#date(2100, 1, 1)) then 366 else 365}
}
)Year | DaysInYear | |
|---|---|---|
| 1 | 2,024 | 366 |
| 2 | 2,023 | 365 |
| 3 | 2,100 | 365 |