Utilix knowledge base
Leap Years and Age Calculations
Published May 1, 2026
A leap year has 366 days instead of 365, with February 29 added to keep the calendar aligned with Earth's orbit around the sun. This extra day creates several edge cases in age calculations, date arithmetic, and software date libraries.
The leap year rule
A year is a leap year if:
- It is divisible by 4, AND
- Not divisible by 100 unless also divisible by 400
2000 → leap year (divisible by 400)
1900 → not a leap year (divisible by 100, not 400)
2024 → leap year (divisible by 4, not 100)
2025 → not a leap year
2100 → not a leap year (divisible by 100, not 400)
The rule produces a calendar year of 365.2425 days on average — accurate enough that the calendar will not noticeably drift for thousands of years.
The February 29 birthday problem
If someone is born on February 29, most jurisdictions have no legal standard for which day they "officially" turn a given age in non-leap years. Developers choose one of two conventions:
| Convention | When Feb 29 birthday ages up |
|---|---|
| Next valid day | March 1 in non-leap years |
| Last valid day of Feb | February 28 in non-leap years |
Neither is universally correct — the right answer depends on the applicable law (for legal age thresholds) or the product's business rules.
In practice, for age-gating features (alcohol purchase, driving licence, voting), rely on the authoritative legal rule for the jurisdiction, not a generic calculator.
How age calculations work in software
Most date libraries compute age as the number of complete calendar anniversaries:
Age = (today.year - birthdate.year) − adjustment
Where adjustment is 1 if the birthday has not yet occurred this calendar year (i.e. the month/day of today is before the month/day of birthdate), otherwise 0.
Potential bug: Some implementations compare month and day numerically and fail on Feb 29 → Feb 28 comparisons in non-leap years, off-by-one-ing the age for Feb 29 birthdays by a year.
Date arithmetic and leap years
Adding "1 year" to a date is not the same as adding 365 days:
- 2024-02-29 + 1 year = 2025-02-28 (or 2025-03-01, depending on library convention)
- 2024-02-29 + 365 days = 2025-03-01
This difference matters for recurring billing, contract renewal dates, and loan terms expressed in years.
When you need a year from today:
- Use your library's
addYears()— it handles February correctly - Avoid
addDays(365)— it ignores leap years
Quick reference: recent and upcoming leap years
2020, 2024, 2028, 2032, 2036, 2040 — every 4 years through 2096, then 2104 (2100 is skipped).
Explore exact date differences including leap-year-aware day counts with the Age Calculator and Date Difference.