“How many days until the deadline?” sounds like a subtraction a child could do. In reality, date arithmetic is a minefield of leap years, uneven months, days that are not 24 hours long, and holidays that move. This article tours the edge cases that make date math hard — so you know when to trust a quick calculation and when to reach for a proper tool.
Skip the traps entirely with the Date Difference Calculator and Age Calculator.
Leap years
The Earth takes about 365.2422 days to orbit the Sun, so a 365-day calendar drifts. Leap years add a day (February 29) to correct it — but not every four years exactly. The full rule:
- 2024 — divisible by 4 → leap year.
- 1900 — divisible by 100 but not 400 → not a leap year.
- 2000 — divisible by 400 → leap year.
That “divisible by 100 but not 400” exception is the one people forget — and a famous bug in older software that wrongly treated 2000 as ordinary.
Uneven months and "add a month"
Months range from 28 to 31 days, which breaks the seemingly simple operation “add one month.” What is January 31 + 1 month? There is no February 31. Systems disagree:
- Some clamp to the last valid day → February 28 (or 29 in a leap year).
- Some overflow into the next month → March 3.
Days that are not 24 hours
On daylight-saving transition days, a local day is 23 or 25 hours long. So “24 hours from now” and “tomorrow at the same time” can be different moments. Code that assumes every day has 86,400 seconds will quietly be an hour off twice a year. This is a major reason to do duration math on absolute timestamps and convert to local time only at the end.
The safe way to count days
The reliable method avoids subtracting calendar fields (which invites the leap-year and month-length traps). Instead:
- Convert both dates to an absolute value — a Unix timestamp, or a count of days since a fixed epoch.
- Subtract the two numbers.
- Divide by the units you want (86,400 seconds per day for elapsed time).
Working in absolute time sidesteps the calendar’s irregularities — the leap years and month lengths are already baked into the timestamp. The same approach underlies an age calculator, which must also decide whether someone born on Feb 29 “has a birthday” in common years.
Business days and holidays
Counting business days adds another layer: you skip weekends, and you skip public holidays — which vary by country, region, and year, and some of which move (the date of Easter, holidays that shift when they fall on a weekend). There is no formula for this; it requires a maintained holiday calendar for the relevant locale, which is exactly why a dedicated tool beats doing it by hand for things like delivery estimates or contract deadlines.
In practice
Date math is hard because the calendar is irregular and the clock is not always steady. The defences are consistent: count in absolute time and convert at the edges, treat “add a month” as ambiguous, remember the full leap-year rule, and never assume a day is 24 hours. For anything that matters, let a tested tool handle the edge cases — the Date Difference and Age calculators do exactly that. See the wider picture in Understanding Dates & Time.
Frequently asked questions
Why is adding a month to a date ambiguous?
Because months have different lengths. "January 31 plus one month" has no February 31, so different systems resolve it differently — some give February 28/29, some roll over to early March. There is no universally correct answer, which is why date libraries document their specific behaviour.
How is a leap year calculated?
A year is a leap year if it is divisible by 4, except years divisible by 100 are not, unless they are also divisible by 400. So 2024 and 2000 are leap years, but 1900 and 2100 are not. This keeps the calendar aligned with the Earth's orbit.
What is the easiest way to count days between two dates?
Convert both to Unix timestamps (or a day count) and subtract, then divide by the seconds in a day. Working in absolute time avoids the month-length and leap-year traps that bite when you try to subtract calendar fields directly.
What are business days?
Business days are weekdays (Monday to Friday) excluding public holidays. Counting them is harder than counting calendar days because you must skip weekends and a holiday list that varies by country and region — which is why dedicated calculators exist.
How do I calculate someone’s exact age?
Subtract the birth date from today, but in whole years, months and days rather than raw days — and account for whether this year’s birthday has happened yet. The leap-year edge case is someone born on February 29, who technically only has a calendar birthday every four years; most systems treat their birthday as February 28 or March 1 in common years.
Why is every fourth year not always a leap year?
The Earth’s orbit is about 365.2422 days, so adding a day every four years slightly over-corrects. The "divisible by 100 but not 400" exception removes three leap days every four centuries to keep the calendar accurate. That is why 2000 was a leap year but 1900 and 2100 are not — a detail that has caused real software bugs.
How long is a day, really?
Usually 24 hours, but not always. On daylight-saving transition days a local day is 23 or 25 hours long, so "24 hours from now" and "tomorrow at the same time" can be different moments. Code that assumes every day is exactly 86,400 seconds quietly goes wrong twice a year, which is why duration maths should be done on absolute timestamps.