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
| Argument | Type | Description |
|---|---|---|
start_date Required | Date | The earlier date. Must be a real Excel date, not text. |
end_date Required | Date | The later date. Must be greater than or equal to start_date, or you'll get #NUM!. |
unit Required | Text | The unit to return: "Y", "M", "D", "YM", "MD", or "YD". Case-insensitive. Wrap in quotes. |
The six units
| Unit | Returns | Example (Jan 15, 2020 → Sep 6, 2026) |
|---|---|---|
"Y" | Complete years between dates | 6 |
"M" | Complete months between dates | 79 |
"D" | Days between dates | 2,426 |
"YM" | Months, ignoring years | 7 (7 months and change past the year mark) |
"MD" | Days, ignoring years and months | 22 (22 days past the last month mark) |
"YD" | Days, ignoring years | 235 |
Basic examples
Age in years
=DATEDIF(A1, TODAY(), "Y")
Tenure in months
=DATEDIF(A1, TODAY(), "M")
Days elapsed
=DATEDIF(A1, B1, "D")
=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"
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")
=endDate - startDate but reads more clearly.4. Subscription time remaining
Days until expiry
=DATEDIF(TODAY(), expiryDate, "D")
=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.
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.
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
If start_date > end_date, DATEDIF returns #NUM!. Either swap the arguments or wrap in IFERROR: =IFERROR(DATEDIF(A1, B1, "Y"), "N/A").
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.
"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
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".