Key facts
- Divide the year by 4. A whole result means a leap year, unless the year is also divisible by 100 and not by 400.
- 2024, 2000 and 2400 are leap years. 2023, 1900 and 2100 are not.
- A leap year has 366 days, which is 52 weeks and 2 days. A common year has 365 days, which is 52 weeks and 1 day.
- The rule repeats every 400 years, giving 97 leap years per cycle and an average year of 365.2425 days.
- In DateUtils, adding one year to 29 February 2024 gives 28 February 2025.
The Gregorian leap year rule
Apply three tests in order:
- The year number divides exactly by 4. If it does not, the year is a common year and the remaining tests are irrelevant.
- If the year also divides exactly by 100, it is a common year, unless the third test applies.
- If the year divides exactly by 400, it is a leap year regardless of the second test.
Stated compactly: divisible by 4, except divisible by 100, except divisible by 400. Only years ending in 00 ever reach the second and third tests, which is why every other year in ordinary use settles at the first.
| Year | Divisible by 4 | Divisible by 100 | Divisible by 400 | Leap year |
|---|---|---|---|---|
| 2024 | Yes | No | No | Yes |
| 2023 | No | No | No | No |
| 1900 | Yes | Yes | No | No |
| 2000 | Yes | Yes | Yes | Yes |
| 2100 | Yes | Yes | No | No |
2024 divided by 4 is exactly 506, so it is a leap year; 2023 leaves a remainder of 3, so it is not. 1900 and 2100 both divide by 100 but not by 400, and are common years. 2000 divides by 400 and is a leap year despite ending in 00.
DateUtils applies this rule to every date it handles, across the whole supported range of years 1 to 9999, as set out in its methodology. The leap year calculator applies the same test to any year and also reports the previous and next leap year on either side of it.
Why century years are treated differently
The solar (tropical) year, measured from one spring equinox to the next, is about 365.2422 days. A calendar that added a day every fourth year without exception would average 365.25 days, running about 11 minutes fast each year and gaining a full day roughly every 128 years. By the time the Gregorian calendar was introduced in 1582, that accumulated error had put the calendar around ten days ahead of the dates the seasons actually followed.
The Gregorian rule keeps 97 of every 400 possible leap days instead of 100, removing the three century years that are not divisible by 400. That produces an average year of 365.2425 days, about 26 seconds longer than the solar year. The residual is small enough to move the equinoxes by only about a day every 3,300 years.
Leap years from 2000 to 2100
Every leap year from 2000 to 2096 is: 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, 2048, 2052, 2056, 2060, 2064, 2068, 2072, 2076, 2080, 2084, 2088, 2092 and 2096. That is 25 leap years in the century from 2000 to 2099, spaced exactly four years apart.
2100 is not a leap year. The next one after 2096 is therefore 2104, a gap of eight years and the only such gap in this period. The same thing happens at 2200 and 2300, while 2400 is a leap year because it divides by 400.
What 29 February does to date arithmetic
Date differences that cross February
Any span covering February is one day longer in a leap year than in the equivalent common year. From 1 January 2024 to 1 March 2024 is 60 days; the same two dates in 2023 give 59. Counting both the first and the last date adds one more, making 61 days for the 2024 span.
The extra day also shifts weekdays. 1 January 2024 was a Monday and 1 March 2024 was a Friday, whereas 1 January 2023 was a Sunday and 1 March 2023 a Wednesday. February holds 29 days in a leap year and 28 in a common year, which the days in month calculator will confirm for any month and year.
Adding a year to 29 February
In DateUtils, month and year arithmetic clamps to the last day of the target month, so 29 February 2024 plus one year is 28 February 2025, never 1 March 2025. The same clamping applies to months: 31 January 2024 plus one month is 29 February 2024, and 31 March 2024 minus one month is 29 February 2024. Because of that, adding a month in two steps can give a different answer from adding two months in one. The adding months reference gives the full rule.
Leap day birthdays
Someone born on 29 February has a birthday only in leap years, which raises the question of when they are treated as turning a year older. The DateUtils age calculator counts a 29 February birthday on 28 February in common years, so a person born on 29 February 2024 turns one on Friday 28 February 2025. Some jurisdictions instead observe the anniversary on 1 March, so legal, tax and school records can disagree with the calculator by a day.
Day 366 and the length of the year
Numbering days from 1, 1 January is day 1 and 31 December is day 365 in a common year. In a leap year 29 February is day 60, every later date moves up by one, and 31 December becomes day 366. A leap year is 52 weeks and 2 days long, so 1 January and 31 December fall on adjacent weekdays and each of those two weekdays occurs 53 times. A common year is 52 weeks and 1 day, so its first and last day fall on the same weekday. The days in year calculator gives the length of any year, month by month.
Leap seconds are a different thing
Leap seconds have nothing to do with leap years. They are inserted into UTC so that atomic time stays aligned with the Earth's rotation, and they are not counted in Unix timestamps, which measure seconds elapsed since 1970-01-01T00:00:00Z with every day treated as exactly 86,400 seconds. A leap day adds 86,400 seconds to the timestamps of a year; a leap second adds nothing to them. The Unix time reference covers the timestamp range and conventions in full.