Skip to content
MeasureMate

Date Difference Calculator

Count the time between two dates as a calendar span in years, months and days and as total days, weeks and hours.

Updated Formula covered by automated tests

Pick a start date and an end date and this tool reports the gap two ways: as a calendar span in years, months and days, and as a plain count of days, weeks and nominal hours. The calendar span is what a contract, a visa or a warranty usually means by "six months"; the day count is what you need for interest accrual, notice periods or a countdown.

The two answers can look inconsistent because months have different lengths. From August 31, 2025 to March 15, 2026 is six months and fifteen days, or 196 days, while the same 196 days starting on July 31, 2025 ends on February 12, 2026, only six months and twelve days later. Both are correct, they simply measure different things, so the result panel shows them side by side.

The end date is not counted, the same way a hotel counts nights: Monday to Tuesday is one day. If your rule says both the first and last day count (common for leave requests and some legal deadlines), add one to the total.

The formula

Total days = N(end) − N(start)
Whole months m = 12 × (Y₂ − Y₁) + (M₂ − M₁), minus 1 if start + m months lands after the end date
Remaining days = N(end) − N(start + m months); years = ⌊m ÷ 12⌋, months = m mod 12
N(date)
Serial day number of a date, counted from a fixed epoch (here 1 January 1970) on the proleptic Gregorian calendar
Y₁, M₁ / Y₂, M₂
Year and month number of the start and end dates
start + m months
The start date moved forward m calendar months; if that day does not exist (31 February), it is pulled back to the last day of the month
m
The number of complete calendar months that fit between the two dates

Counting days is easy once every date is turned into a serial number, the same trick astronomers use with Julian Day numbers and spreadsheets use with date serials. Subtracting two serials gives the exact count with leap years already built in, because the conversion follows the Gregorian rule: a year is leap if it divides by 4, except century years, which must also divide by 400.

The years-months-days figure is trickier because "one month" is not a fixed length. This calculator steps forward from the start date by whole calendar months, clamping to the last day of a short month, until one more month would overshoot, then counts the leftover days. That keeps every part non-negative, which a naive field-by-field subtraction does not.

All arithmetic is done on calendar dates rather than clock times. A daylight-saving weekend contains a 23-hour or 25-hour day, and dividing milliseconds by 86,400,000 in local time can quietly lose or gain a day; working with date serials avoids that.

Worked example

Priya started a consulting assignment on August 31, 2025 and it ends on March 15, 2026. Her contract quotes the length in months and days, and the invoice needs the exact number of days.

  1. 1 Raw month count: 12 × (2026 − 2025) + (3 − 8) = 7 months.
  2. 2 August 31 plus 7 months is March 31, 2026, which is after March 15, so drop to 6 whole months.
  3. 3 August 31 plus 6 months would be February 31; February 2026 has 28 days, so the anchor is February 28, 2026.
  4. 4 Days left from February 28 to March 15: 15 days, giving 6 months and 15 days.
  5. 5 Total days: 0 (Aug 31 itself) + 30 (Sep) + 31 (Oct) + 30 (Nov) + 31 (Dec) + 31 (Jan) + 28 (Feb) + 15 (Mar) = 196 days, which is exactly 28 weeks.

Result: The assignment lasts 6 months and 15 days, or 196 days (28 weeks). Counting both the first and the last day, as some timesheets do, makes it 197.

Before you rely on the result

  • Dates are on the Gregorian calendar extended backward. For historical dates before a country adopted it (1752 in Britain and its colonies, 1918 in Russia), the day count will not match records kept in the Julian calendar.
  • The calculator works with whole dates only, not times of day, so it cannot measure a span like 9:00 on one day to 17:30 on another.

Frequently asked questions

Why do two date ranges with the same number of days give different months?

A month is 28 to 31 days long, so the same day count covers a different number of whole months depending on which months fall inside the range. January 1 to March 1 is 59 days and exactly two months in a common year; July 1 to August 29 is also 59 days but only one month and 28 days.

What does the calculator do with a start date of January 31?

January 31 plus one month has no February 31, so it is treated as the last day of February. From January 31 to March 1, 2025 the result is 1 month and 1 day. Some spreadsheet functions handle month ends differently, so a result can differ from another tool by a day in these edge cases.

Should I add one day to the result?

Only if your rule counts both endpoints. Rental nights, interest days and ages exclude one end; vacation day requests, event durations ("June 3 through June 7 is five days") and some statutory deadlines include both. Check the wording of the document you are working from.

Does the total in hours account for daylight saving time?

The hours figure is days × 24, so it assumes every day is 24 hours long. If the range crosses a clock change in your area, the real elapsed time between the same wall-clock times is one hour shorter (spring) or longer (autumn).

Sources

All time & dates