Calculate calendar months between two dates

Calendar months have unequal lengths, so a month difference needs a calendar rule. This guide explains whole-month stepping, shorter-month clamping, and the remaining-day calculation.

How days, weeks, and months between dates are calculated

Months are counted in whole calendar months from the earlier date: we add one month at a time (with day-of-month clamping) until the next step would go past the later date. The remainder is leftover days.

Total days are the number of calendar days from the first date to the second, not counting the start date but counting the end date. January 1 to January 31 is 30 days.

If the second date is earlier than the first, you still get the same span; the summary lists the earlier date first.

Date difference examples

  • 2026-01-15 → 2026-02-1531 days, about 4.43 weeks, 1 month and 0 days.