Date Arithmetic: How to Calculate Days, Weeks, and Months Between Dates
Calculating the time between two dates seems simple but has hidden complexity from varying month lengths, leap years, and boundary edge cases.
Days: The fundamental unit. Counting the 24-hour periods between two calendar dates gives an exact integer. This is deterministic: from June 1 to July 1 is always 30 days. From January 1 to February 1 is 31 days. The calculation correctly accounts for leap years (February 29 adds one day).
Weeks: Simply divide the days count by 7. A 30-day span is 4.29 weeks. Weeks are straightforward because they have a fixed length.
Months: The most ambiguous unit because months have different lengths (28–31 days). Two common approaches: (1) Decimal months = days ÷ 30.44 (average month length accounting for leap years). This gives a consistent approximate value. (2) Calendar months — counting how many times the same day of the month occurs. This varies by the specific months involved.
Years: Similar to months — decimal years = days ÷ 365.25 (accounting for leap years). For exact calendar years, count completed birth-anniversaries.
Edge cases: Month boundaries are the trickiest. From January 31 to March 1 is either 28 or 29 days depending on whether it's a leap year. From a Friday to the following Monday is 3 days in calendar counting but spans a weekend. Use Tooler's Date Difference Calculator for instant, accurate date differences.