Leap years and date arithmetic: why calendar math isn't simple division
Finding the time between two dates looks like it should be one subtraction. It isn't, because the calendar itself isn't uniform — months range from 28 to 31 days, and roughly one year in four has an extra day.
Why the leap year rule isn't just "every four years"
The actual rule: a year is a leap year if it's divisible by 4, except century years, which must be divisible by 400. That's why 2000 was a leap year but 1900 was not, even though both are divisible by 4 — 1900 isn't divisible by 400. Any date calculation spanning a century boundary needs to apply this exception correctly or it will be off by a day.
Why "divide by 365.25" isn't quite right either
Averaging in the leap-year day (365.25 days per year) gets you close for very rough estimates, but it isn't exact for any specific pair of dates — it smooths over the actual pattern of which years are leap years and where the extra day falls relative to your two dates. For an exact answer, the two dates need to be compared directly on the calendar, not approximated with an average.
How calendar-aware calculation works
The correct method compares year, month, and day fields directly, the same way you'd do long subtraction by hand: subtract days first, and if that goes negative, borrow a month (adding that month's actual day count, which varies); subtract months next, and if that goes negative, borrow a year. The result is exact because it's built from the real calendar structure rather than an average.
Where this matters
For a rough sense of "how many years apart," the difference between averaged and calendar-aware math is usually invisible. It stops being invisible anywhere an exact day count has a real consequence — age-based eligibility cutoffs, contract terms measured in exact months, or interest calculations that compound based on actual elapsed days.