Excel DATEDIF Function: Complete Guide (2026)
Home›Functions›Date & Time›DATEDIF
ExcelFunction Reference⏱ 7 min read

Excel DATEDIF Function: Complete Guide

DATEDIF calculates the difference between two dates in years, months, or days. It's the go-to for age, tenure, and duration math. And here's the kicker: it's a legacy function that Microsoft never officially documented — but it works in every version of Excel and Google Sheets.

Syntax

DATEDIF(start_date, end_date, unit)
ArgumentTypeDescription
start_date RequiredDateThe earlier date. Must be a real Excel date, not text.
end_date RequiredDateThe later date. Must be greater than or equal to start_date, or you'll get #NUM!.
unit RequiredTextThe unit to return: "Y", "M", "D", "YM", "MD", or "YD". Case-insensitive. Wrap in quotes.

The six units

UnitReturnsExample (Jan 15, 2020 → Sep 6, 2026)
"Y"Complete years between dates6
"M"Complete months between dates79
"D"Days between dates2,426
"YM"Months, ignoring years7 (7 months and change past the year mark)
"MD"Days, ignoring years and months22 (22 days past the last month mark)
"YD"Days, ignoring years235

Basic examples

Age in years

=DATEDIF(A1, TODAY(), "Y")
If A1 = 1990-05-15 → Result: 36

Tenure in months

=DATEDIF(A1, TODAY(), "M")
If A1 = hire date → Result: months of employment

Days elapsed

=DATEDIF(A1, B1, "D")
Days between start and end. Same as =B1-A1.

The classic age string

Combine three DATEDIF calls to build "35 years, 7 months, 22 days":

Full age breakdown

=DATEDIF(A1,TODAY(),"Y") & " years, " &
 DATEDIF(A1,TODAY(),"YM") & " months, " &
 DATEDIF(A1,TODAY(),"MD") & " days"
Result: 35 years, 7 months, 22 days

Common uses

1. Age from birthday

Complete years old

=DATEDIF(A1, TODAY(), "Y")

2. Employee tenure (years and months)

"2 years, 3 months"

=DATEDIF(A1, TODAY(), "Y") & " yr " & DATEDIF(A1, TODAY(), "YM") & " mo"

3. Project duration

Days between start and end

=DATEDIF(startDate, endDate, "D")
Same result as =endDate - startDate but reads more clearly.

4. Subscription time remaining

Days until expiry

=DATEDIF(TODAY(), expiryDate, "D")
Returns #NUM! if expired. Wrap in IFERROR: =IFERROR(DATEDIF(TODAY(), A1, "D"), "Expired")

5. Loan age in months

Months since origination

=DATEDIF(originationDate, TODAY(), "M")

The MD bug

DATEDIF's "MD" unit has a known bug: it sometimes returns negative numbers or unexpected values around month boundaries. Microsoft acknowledges the bug but recommends using "MD" only when accuracy isn't critical.

Alternative to MD for exact day count

Instead of DATEDIF(A1, B1, "MD"), use B1 - EDATE(A1, DATEDIF(A1, B1, "M")). This gives the exact day difference past the last complete month.

Why DATEDIF isn't in autocomplete

DATEDIF originated in Lotus 1-2-3. Microsoft included it for compatibility when Excel launched. It remains in every version — Excel 365, Excel 2019, Excel 2016, Excel for Mac, and Google Sheets — but Microsoft never officially documented it in their function reference. Autocomplete doesn't suggest it. You have to type the whole name.

DATEDIF is safe to use

Despite the "undocumented" status, DATEDIF has worked identically for 30+ years. It's not going away — too many financial models depend on it. Use it without worry.

Common pitfalls

#NUM! error

If start_date > end_date, DATEDIF returns #NUM!. Either swap the arguments or wrap in IFERROR: =IFERROR(DATEDIF(A1, B1, "Y"), "N/A").

#VALUE! error

Happens when start_date or end_date isn't a real date (e.g., stored as text). Fix with DATEVALUE() or verify the source data type.

Unit case doesn't matter but quotes do

"Y", "y", "YEAR" — Excel accepts variations. But DATEDIF(A1, B1, Y) without quotes references cell Y in the current row. Always quote the unit.

DATEDIF alternatives (modern approach)

For pure year, month, day math without DATEDIF's baggage:

Years:  =YEAR(B1) - YEAR(A1) - (DATE(YEAR(A1), MONTH(B1), DAY(B1)) < A1)
Days:   =B1 - A1

The years formula subtracts 1 if the birthday hasn't happened yet this year. Verbose, but doesn't depend on undocumented functions.

DATEDIF in Google Sheets

Google Sheets has an identical DATEDIF function. Same syntax, same six units, same MD bug. Sheets does document DATEDIF officially (unlike Excel).

Related functions

Related

TODAY

Perfect DATEDIF companion for "days from today" math.

Related

EDATE

Add N months to a date — complements DATEDIF for month math.

Related

NETWORKDAYS

For business-day math instead of calendar-day math.

Related

YEAR / MONTH / DAY

Building blocks for DATEDIF alternatives.

Excel Wizard

Age math without the DATEDIF gotchas

DATEDIF has an "MD" bug, isn't in autocomplete, and returns #NUM! when arguments are reversed. Excel Wizard writes age and tenure formulas with the right units, error handling, and format — no need to remember which unit does what.

Install Excel Wizard →

Frequently asked questions

What does DATEDIF do in Excel?

DATEDIF calculates the difference between two dates in years, months, or days. Syntax: =DATEDIF(start_date, end_date, unit) where unit is Y, M, D, YM, MD, or YD.

Why is DATEDIF not showing in the Excel autocomplete?

DATEDIF is a legacy function from Lotus 1-2-3 that Microsoft never officially documented. It works in every version of Excel but doesn't appear in autocomplete. You have to type the whole name.

What units can DATEDIF use?

Six units: Y (complete years), M (complete months), D (days), YM (months excluding years), MD (days excluding years and months), YD (days excluding years).

How do I calculate age in years, months, and days?

Combine three DATEDIF calls: =DATEDIF(A1,TODAY(),"Y")&" years, "&DATEDIF(A1,TODAY(),"YM")&" months, "&DATEDIF(A1,TODAY(),"MD")&" days".