Home  /  Blog  /  Date & Text
Date & Text

Months Between Two Dates in Excel (DATEDIF and 3 Other Ways)

By admin 26 November 2026 Date & Text

You have two dates — a start date and an end date — and you want the months between them. Subtracting the dates only gives you days, and dividing the days by 30 is wrong, because months are not all 30 days long. Excel has a function for this, DATEDIF, but it does not appear when you type it, and it is not the only way: the same two dates can give you four different answers, and all four can be right, because they count different things. This guide gives you the formula first, works it through on real dates, shows you the four methods side by side on the same two pairs of dates, and tells you which one matches what you mean — plus the two errors that catch everyone, #NUM! and #VALUE!.

Quick takeaway: decide which months you mean, then pick the formula.

  • Whole completed months: =DATEDIF(A2,B2,"m")
  • Calendar months (month boundaries crossed): =(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)
  • Decimal months, partial months included: =YEARFRAC(A2,B2)*12
  • Months up to today: =DATEDIF(A2,TODAY(),"m")
  • DATEDIF does not appear in Excel’s function list — type the whole name yourself.
  • Start date after end date gives #NUM!.
Months Between Two Dates in Excel (DATEDIF and 3 Other Ways)

First, Decide Which Months You Mean

Four methods, four answers for the same two dates. The rule is:

DATEDIF counts months you have finished living through. The YEAR and MONTH method counts month labels you have passed.

  • If someone started on 15 January and it is now 20 August, they have finished 7 whole months. DATEDIF says 7.
  • If someone started on 31 December and it is now 1 January, they have finished 0 whole months — but they have crossed from December into January, one month boundary. The calendar method says 1, DATEDIF says 0. Both are right; they answer different questions.

Decide which one your business rule means before you pick a formula. For length of service, age and invoices, you almost always mean completed months — DATEDIF. For “how many calendar months does this span”, you mean the calendar method.

The DATEDIF Formula — Whole Completed Months

=DATEDIF(start_date, end_date, "m")
  • start_date is the earlier date.
  • end_date is the later date.
  • “m” is the unit, in double quotes — it means complete months.

DATEDIF counts full months and ignores any leftover days that do not form another whole month.

Why does DATEDIF not appear when you type it? Microsoft does not document it and it is not in Excel’s function list or wizard — it is kept for compatibility with older spreadsheet programs. It works in every current version of Excel. You just have to type the whole name yourself, with no suggestion and no argument tooltip. If you type it correctly, Excel accepts it.

Worked Example — 15 January 2023 to 20 August 2023

Start date in A2, end date in B2:

=DATEDIF(A2,B2,"m")

Result: 7. Seven complete months have passed. The extra 5 days are discarded, not rounded.

The boundary matters: 15 January to 14 March returns 1, because two complete months have not passed. 15 January to 15 March returns 2 — the second monthly step lands exactly on 15 March.

The Four Methods Side by Side

The same formula, applied to two pairs of dates. The second pair is deliberately awkward, because that is where the methods separate.

MethodFormula15 Jan 2023 → 20 Aug 202331 Dec 2023 → 1 Jan 2024What it actually counts
DATEDIF=DATEDIF(A2,B2,"m")70Completed whole months, leftover days discarded
Calendar months=(YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)71Month boundaries crossed, day of month ignored
YEARFRAC=YEARFRAC(A2,B2)*127.17about 0.03Elapsed time as a decimal, partial months included
Rounded up=ROUNDUP(YEARFRAC(A2,B2)*12,0)81Any part of a month counts as a full month

Check the calendar column: for 31 December 2023 to 1 January 2024, (2024 − 2023) × 12 + 1 − 12 = 12 − 11 = 1. One boundary crossed, even though only one day passed. And YEARFRAC for that pair is about 0.03 — one day is roughly three hundredths of a month.

Worked Example — Length of Service in Years and Months

Someone started work on 10 March 2021. Today is 10 September 2025. How long have they worked here?

  • Complete months: =DATEDIF(A2,B2,"m") = 54. Check it: (2025 − 2021) × 12 + (9 − 3) = 48 + 6 = 54.
  • Complete years: =DATEDIF(A2,B2,"Y") = 4.
  • Months left after the complete years: =DATEDIF(A2,B2,"YM") = 6. “YM” counts the months ignoring the years — 54 months is 4 years and 6 months.
  • Together, as text: =DATEDIF(A2,B2,"Y")&" years, "&DATEDIF(A2,B2,"YM")&" months" = “4 years, 6 months”.

The same pattern works for age: start date is the date of birth, end date is TODAY(), and “Y” gives the age in whole years.

One warning: Microsoft recommends you do not use the “MD” unit (days ignoring months and years). In some cases it gives a negative number, zero, or a wrong result. Use “Y” and “YM” for years and months, and subtract the dates for days.

Months From a Date to Today — With TODAY()

To count months from a start date up to today, and have the answer update every day:

=DATEDIF(A2,TODAY(),"m")

TODAY() supplies the current date, and Excel updates the result whenever the workbook recalculates. To count the complete months remaining from today to a planned end date:

=DATEDIF(TODAY(),B2,"m")

Two warnings: the first formula returns #NUM! if the start date is in the future. The second returns #NUM! after the planned end date has passed. Check the date order before using either one.

Months Between Dates Without DATEDIF

If you do not want to use DATEDIF — for example, because a colleague will not trust a function that does not appear in the list — you can calculate completed months with YEAR, MONTH and DAY:

=12*(YEAR(B2)-YEAR(A2))+MONTH(B2)-MONTH(A2)-(DAY(B2)<DAY(A2))

How it works: the first part counts calendar months, and the last part subtracts 1 when the end day is earlier in the month than the start day — because the final month is not complete yet. For 15 January to 20 August: 12 × 0 + 8 − 1 − 0 = 7. For 15 January to 14 March: 12 × 0 + 3 − 1 − 1 = 1. Same answers as DATEDIF, with no hidden function.

Common Mistakes

MistakeWhat happensFix
You subtracted the dates and divided by 30Wrong — months are 28 to 31 days longUse DATEDIF with “m”
You used DATEDIF and got 0, but the dates are in different monthsCorrect — no whole month has finished yetIf you meant month boundaries, use the calendar formula
You typed DATEDIF and nothing appearedIt is not in Excel’s function list — no suggestion, no tooltipType the whole name yourself; Excel accepts it
Start date is after the end date#NUM! errorSwap the dates, or check the date order first
A date is stored as text, not as a date#VALUE! errorFix the source date — convert it to a real date, do not hide the error
You used “MD” for the leftover daysCan give a negative number, zero, or a wrong resultDo not use “MD” — Microsoft recommends against it
You used TODAY() and the answer changed overnightThat is the point — TODAY() is always the current dateIf you need a fixed answer, type the date instead of TODAY()
You counted months to today for a future start date#NUM! — the start date has not happened yetCheck the date order before using the formula

Frequently Asked Questions

How do I calculate months between two dates in Excel? Use =DATEDIF(A2,B2,"m") for completed whole months. A2 is the start date, B2 is the end date, and “m” is the unit in double quotes.

Why does DATEDIF not show up in Excel? Microsoft does not document it and it is not in the function list. It works in every current version — type the whole name yourself, with no suggestion or tooltip.

How many months are between 15 January 2023 and 20 August 2023? 7 complete months with DATEDIF. 7 calendar months with the YEAR/MONTH formula. About 7.17 decimal months with YEARFRAC × 12. The right answer depends on which months you mean.

How do I count months between two dates including partial months? Use =YEARFRAC(A2,B2)*12 for a decimal answer, or =ROUNDUP(YEARFRAC(A2,B2)*12,0) to count any part of a month as a full month.

How do I get years and months between two dates? Use “Y” for the years and “YM” for the leftover months: =DATEDIF(A2,B2,"Y")&" years, "&DATEDIF(A2,B2,"YM")&" months". For 10 March 2021 to 10 September 2025 that gives “4 years, 6 months”.

Why does DATEDIF return #NUM!? The start date is after the end date. Swap them, or check the date order first.

How do I count months from a date to today? Use =DATEDIF(A2,TODAY(),"m"). TODAY() is the current date, so the answer updates every day.

Can I calculate months between dates without DATEDIF? Yes: =12*(YEAR(B2)-YEAR(A2))+MONTH(B2)-MONTH(A2)-(DAY(B2)<DAY(A2)). It gives the same completed months as DATEDIF.

That is the whole method: one function, DATEDIF with “m”, for the months you have finished living through — and the calendar formula, YEARFRAC or ROUNDUP when you mean something else. The only cases that need extra care are the start date coming after the end date, a date stored as text, and the “MD” unit that Microsoft itself warns against. Try it on your own dates now, with the 15 January to 20 August example above, and when you need to go the other way — adding months to a date instead of counting between two — the next guide to read is the add months to a date guide, which uses EDATE and EOMONTH for exactly that job.


About admin

Author of Excel formula guides on this blog.

View all guides by admin →

Keep Learning

Related guides