Menu

DATEDIF in Excel: Years, Months and Days Between Dates

=DATEDIF(A2,B2,"M") counts the complete months between the start date in A2 and the end date in B2. The units Y, M, D, YM, MD and YD, why DATEDIF is missing from the function list, and the #NUM! error.

Every sheet on this page is live: change a number or a formula and it recalculates.

=DATEDIF(A2,B2,"M") counts the complete months between the start date in A2 and the end date in B2. The third argument, the unit, decides what is counted: "Y" years, "M" months, "D" days, plus three units that ignore part of the dates.

Every DATEDIF unit on one pair of dates
E3
ABCDE
1StartEndUnitResult
22024-04-152026-09-10Y2
3M28
4D878
5YM4
6MD26
7YD148
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

From 2024-04-15 to 2026-09-10 there are 2 complete years, 28 complete months and 878 days. Change the end date in B2 and watch each unit move. The unit can be typed in the formula ("M") or, as here, read from a cell.

DATEDIF syntax and units

=DATEDIF(start_date, end_date, unit)
UnitCounts2024-04-15 to 2026-09-10
"Y"complete years2
"M"complete months28
"D"days878
"YM"months after the last complete year4
"MD"days after the last complete month26
"YD"days after the last complete year148

"Complete" means DATEDIF never rounds up. From January 31 to February 28 is 0 months, because February 28 comes before the one-month mark. The unit is not case-sensitive ("m" works too), but it must be in quotes or in a cell.

Why DATEDIF is not in the function list

DATEDIF came to Excel from Lotus 1-2-3, and Microsoft keeps it only for compatibility. It is not in the Insert Function dialog, formula autocomplete does not suggest it, and no tooltip shows its arguments. It still calculates in every version of Excel on Windows and Mac, and in Google Sheets. Type the whole name and the opening bracket, =DATEDIF(, and add the arguments yourself.

Months between two dates

Complete months are what most contracts, subscriptions and tenure reports need. For a decimal figure, YEARFRAC(A2,B2)*12 returns the months with the fraction kept (its default basis counts every month as 30 days).

Months of each subscription
C2
ABCD
1StartEndFull monthsDecimal months
22025-03-102026-01-0599.8
32024-04-152026-09-102828.8
42026-01-312026-02-2800.9
52025-11-012026-05-0166.0
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The first subscription ran 9 complete months: January 5 is before the 10th, so the tenth month is not counted. The third row shows the January 31 case, 0 months.

Years, months and days together

"Y", "YM" and "MD" are made to be used together. Each one picks up where the previous one stopped, so the three answer "how long, exactly": 2 years, 4 months and 26 days for the dates above. Calculate age uses the same three units on birth dates.

Length of service
E2
ABCDEF
1HiredYearsMonthsDaysServiceAs of
22019-06-0373277y 3m 27d2026-09-30
32023-11-20210102y 10m 10d
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The first employee has served 7 years, 3 months and 27 days on 2026-09-30.

Why DATEDIF returns #NUM!

DATEDIF refuses to count backwards. When the start date is later than the end date, the result is #NUM!. If the order can vary, give DATEDIF the earlier date with MIN and the later one with MAX.

Start date after the end date
C2
ABCD
1StartEndDATEDIFWith MIN and MAX
22026-03-102026-01-05#NUM!64
#NUM! A number is out of range for this function.

C2 shows #NUM!; D2 returns 64. For days alone, =ABS(B2-A2) gives the same 64 without DATEDIF. DATEDIF also returns #NUM! for an unknown unit such as "W", and #VALUE! when a date is text that Excel cannot read as a date.

The MD unit can be wrong

Microsoft's own documentation advises against "MD": when the start day does not exist in the month before the end date, it can return a negative number.

MD from January 31
C2
ABCD
1StartEndMDD
22026-01-312026-03-01-229
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

From January 31 to March 1 the "MD" result is -2: DATEDIF counts from "February 31", which rolls over to March 3, two days after the end date. The day count, 29, is right. When start dates can fall on the 29th to the 31st, show the length in days, or check the MD figure by hand.

Practice: count the months

Your turn
C2
ABC
1StartEndMonths
22025-03-102026-01-05
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, count the complete months between the start date in A2 and the end date in B2.

Your turn: either order
C2
ABC
1Date 1Date 2Days
22026-04-182026-02-01
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, count the days between the two dates, whichever one comes first.

Frequently Asked Questions

What does DATEDIF do in Excel?

It counts the complete years, months or days between two dates: =DATEDIF(A2,B2,"Y") for years, "M" for months, "D" for days. The start date must come first.

Why can't I find DATEDIF in Excel?

DATEDIF is kept for compatibility with Lotus 1-2-3, so Excel leaves it out of the Insert Function dialog and formula autocomplete. It still works in every version: type =DATEDIF( in full and add the arguments yourself.

Why does DATEDIF return #NUM!?

The start date is later than the end date. Swap the arguments, or use =DATEDIF(MIN(A2,B2),MAX(A2,B2),"D") when you don't know which date comes first.

What is the difference between YM, MD and YD in DATEDIF?

They ignore part of the dates: "YM" gives the months left after the full years, "MD" the days left after the full months, and "YD" the days left after the full years. Together "Y", "YM" and "MD" give an age in years, months and days.

Does DATEDIF work in Google Sheets?

Yes, with the same arguments and units. Google Sheets also lists it in its function help, unlike Excel.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED