Calendar arithmetic without a spreadsheet
Dates look like simple numbers until you subtract across month ends, ask whether a year is a leap year, or compute someone’s exact age in years, months, and days. The Date family focuses on Gregorian calendar math in the browser: whole-day gaps, leap-year rules, and age breakdowns against a reference date.
To measure how many midnights separate two calendar days, use days between.
What this family computes
- Days between — whole-day difference between a start date and an end date, using UTC midnight boundaries so local timezone clock times do not shift the day count unexpectedly.
- Leap year — apply Gregorian leap-year rules for years from 1 to 9999 and answer yes/no.
- Calculate age — exact years, months, and days between a birth date and a reference date using calendar arithmetic (not a fixed 365.25-day approximation).
These helpers answer calendar questions. They are not astronomy ephemerides, payroll systems, or legal age-of-majority advisors for every jurisdiction.
Whole-day differences
Counting days between dates depends on definitions. Inclusive vs exclusive ranges confuse humans (“from Monday to Friday” might mean four nights away or five weekdays). The days-between tool targets the whole-day difference with UTC midnight boundaries so 2026-01-01 to 2026-01-02 is one day of separation in the usual absolute-difference sense.
When planning travel or leave, clarify whether you need:
- Number of midnights crossed
- Number of weekdays (business days)
- Inclusive ticket nights
Business-day and holiday-aware planning belongs with Holidays and workplace calendars, not pure day deltas.
Gregorian leap years
A Gregorian year is a leap year if it is divisible by 4, except century years must be divisible by 400. So 2000 was a leap year; 1900 was not; 2024 was; 2100 will not be. Leap year encodes those rules for any year in 1…9999.
Leap days affect February 29 birthdays, interest accruals, and “one year later” date math. Age calculators must decide how to treat Feb 29 births in common years—implementations document their convention; do not assume every system agrees.
Exact age in Y/M/D
Calculate age walks calendar units: complete years, then months, then leftover days between a birth date and a reference date. That matches how people talk about age (“32 years, 4 months, 12 days”) better than dividing total days by 365.25.
Choose the reference date carefully: “today” for current age, or a historical date for “how old on that day.” Time-of-day is out of scope when inputs are calendar dates only; someone born in the evening may still be “a day younger” than a wall-clock intuition suggests if you only store dates.
Choosing among Date vs Time tools
| Question | Prefer |
|---|---|
| How many whole days between two dates? | Days between |
| Is year Y a leap year? | Leap year |
| Age as years/months/days? | Calculate age |
| Elapsed years/months/weeks/days/hours… with richer breakdown? | Time elapsed / date difference |
| Live countdown to an instant | Countdown |
Date tools emphasize civil calendar rules; Time tools add durations, countdowns, and travel estimates.
Edge cases worth knowing
- Timezone. Storing only
YYYY-MM-DDavoids many clock bugs; converting from timestamps can shift the calendar day near midnight UTC offsets. - Historical calendars. Gregorian rules retroactively applied to year 1 are a computational convenience, not a claim about how people in antiquity kept time.
- Order. Swapping start and end may yield a signed or absolute difference depending on the tool—read the result labels.
- Legal age. “18 years old” for contracts may use jurisdiction-specific cutoffs; verify with local law.
Limitations
- No payroll holidays or business-day calendars inside Date alone.
- No lunar or fiscal calendars.
- Not medical gestational calculators.
- Browser locale affects display formatting more than the underlying arithmetic.
Related tooling
See also Time, Easter, and Holidays for movable feasts and leave planning.
Summary
Date tools perform Gregorian day counts, leap-year checks, and exact age breakdowns. Prefer them for clear calendar questions; escalate to Time and Holidays when you need countdowns, richer duration units, or national fixed holidays in a leave plan.