Date Difference Calculator

Count the days, weeks, months and years between two dates, including the DATEDIF formula and a fix for the negative remaining-days bug.

Dates are treated as calendar dates with no time of day and no time zone shift. The default range is 15 January 2024 to 12 November 2026: 1,032 days, or 2 years, 9 months and 28 days.

Quick answer: in Excel or Google Sheets, with the start date in B2 and the end date in C2, the number of days is:

=DATEDIF(B2, C2, "D")

=C2-B2 gives the same day count, as long as you format that cell as a number. If it shows a date such as 28 April 1902, the value is right and the format is wrong. Both dates must be real date values, not text that happens to look like a date. If you inherited a column of text dates, fix that first with the steps in Dates stored as text.

The default example: 15 January 2024 to 12 November 2026

I ran this range in Google Sheets on 12 November 2026:

=DATEDIF(DATE(2024,1,15), DATE(2026,11,12), "D")
=DATEDIF(DATE(2024,1,15), DATE(2026,11,12), "Y")
=DATEDIF(DATE(2024,1,15), DATE(2026,11,12), "YM")
=DATEDIF(DATE(2024,1,15), DATE(2026,11,12), "MD")
=DATEDIF(DATE(2024,1,15), DATE(2026,11,12), "M")

Those returned 1,032 days, 2 years, 9 leftover months, 28 leftover days (the "MD" unit happens to be right on this range), and 33 complete months.

So the span is 1,032 days, which is 147 weeks and 3 days, or 2 years, 9 months and 28 days, or 33 complete months plus 28 days. Adding 1 gives the inclusive count (1,033 calendar dates from the first day through the last).

Same-day start and end is 0 days, or 1 day if you include the start date. 31 December 2025 to 1 January 2026 is 1 day. A year later on the same calendar date, 12 November 2025 to 12 November 2026, is 365 days in this case, and "Y" returns 1.

Years, months and the DATEDIF “MD” bug

A combined “2 years, 9 months, 28 days” result is usually written like this:

=DATEDIF(B2,C2,"Y")&" years, "&DATEDIF(B2,C2,"YM")&" months, "&DATEDIF(B2,C2,"MD")&" days"

That is the same pattern used for ages in Calculate age from a date of birth. It is fine on many ordinary ranges. It is not fine on some month-end dates, because the "MD" unit can come back negative.

In Google Sheets, 31 January 2024 to 1 March 2024 gives:

  • DATEDIF(...,"D") = 30 days (correct)
  • DATEDIF(...,"M") 与 "YM" = 1 month (correct)
  • DATEDIF(...,"MD") = −1 (not a useful remaining-day count)

The calculator does not use raw "MD" for the years-months-days line. After the complete months, it counts the leftover days the same way as this formula, which returned 1 for that 31 January–1 March example:

=C2-EDATE(B2, DATEDIF(B2,C2,"M"))

EDATE moves the start date forward by a whole number of months and clips to the last day of the month when needed (31 January plus one month becomes 29 February 2024, then 1 March is one day later). If you paste a “years, months, days” formula into a sheet, use that remainder instead of "MD".

Inclusive vs exclusive days

Hotels, timesheets and “how many days is this ticket open” often want both ends counted. 1 March to 3 March is 2 days by subtraction and 3 days inclusive. Tick the box above, or add 1:

=DATEDIF(B2,C2,"D")+1

If you need working days rather than calendar days, and you want weekends or a holiday list taken out, that is a different function (NETWORKDAYS 或 NETWORKDAYS.INTL). This page only counts calendar dates.

Questions that come up

How do I calculate the number of days between two dates in Excel or Google Sheets?

If the start date is in B2 and the end date is in C2, =C2-B2 or =DATEDIF(B2,C2,"D") returns the number of days. Format the result as a number, not as a date.

Does the count include both the start date and the end date?

The plain subtraction and DATEDIF "D" do not: 1 January to 2 January is 1 day. Tick “Include the start date” in the calculator, or add 1, when you need the inclusive count (two calendar dates).

Why does DATEDIF sometimes return a negative number of days?

The "MD" unit is unreliable when the start day number is later in the month than the end day, for example 31 January to 1 March 2024. Use =C2-EDATE(B2,DATEDIF(B2,C2,"M")) for the remaining days after complete months.

Oscar

专注电子表格公式与排错;具体测试环境和待验证事项见各篇文章。

Tested in Google Sheets on 12 November 2026 (DATEDIF, EDATE and the sample dates on this page). DATEDIF and EDATE also exist in Excel; I did not re-run these cases in Excel this session.