DATEDIF Function in Excel: Ultimate Guide

DATEDIF Function in Excel: Ultimate Guide
IL Inar Learn
DATEDIF Function in Excel — Ultimate Guide Saved
12 min read Excel 2016 · 2019 · 2021 · Microsoft 365 Updated for 2026

DATEDIF is Excel’s best-kept secret. It is not listed in the function wizard, it does not autocomplete, and it has no tooltip — yet it is the only built-in way to get complete years, months, and days between two dates in a single function family. Everyone who has ever calculated an age or a tenure in Excel has eventually stumbled onto it.

This guide covers the full syntax, all six unit codes, five real-world example workbooks (age, tenure, project duration, warranty countdown, subscription cycle), the alternatives you should consider instead, the notorious "MD" bug, and a 5-question exam to test yourself.

In one sentence

DATEDIF returns the difference between two dates in complete years, months, or days, written as =DATEDIF(start_date, end_date, unit).

01

What Is the DATEDIF Function?

DATEDIF measures the interval between two dates. Unlike a simple subtraction (=B2-A2), which returns the raw day count, DATEDIF can return the interval expressed in complete years, complete months, or days — and it can return the remaining months or days after whole years have been removed. That last part is why it exists.

The function dates back to Lotus 1-2-3. Microsoft kept it in Excel for spreadsheet compatibility but never documented it in the user interface. That is why you cannot find it by typing =DATE and looking through the dropdown — you have to know the name and type it in full.

FunctionDATEDIF
CategoryDate & Time
Arguments3 (all required)
ReturnsWhole number
Hidden?Yes

A simple age, drawn out

Take the formula =DATEDIF(A2, TODAY(), "Y"). Excel reads it in three steps: check the start date, check the end date, then count how many complete years sit between them.

Excel — Book1.xlsxSheet1
A
Birthdate
B
Age (Years)
C
Formula in B2
21990-05-1534=DATEDIF(A2,TODAY(),”Y”)
32001-11-0323=DATEDIF(A3,TODAY(),”Y”)
41985-02-2040=DATEDIF(A4,TODAY(),”Y”)
Note the boundary case: the “Y” unit returns complete years. If today is 2025-03-10 and the birthdate is 1990-05-15, the result is 34 — the 35th birthday has not yet happened, so the year does not count.
i
Why Microsoft hides it

DATEDIF is a compatibility holdover. Microsoft keeps it working because removing it would break millions of legacy spreadsheets, but they do not promote it because the "MD" unit has known accuracy issues and they would prefer you use YEARFRAC or DAYS.

02

Syntax and Arguments

All three arguments are required. There is no optional third argument, and there is no fourth argument for time.

Formula syntax
=DATEDIF(start_date, end_date, unit)
The three arguments of the DATEDIF function
ArgumentRequired?What it does
start_dateRequiredThe earlier date. Can be a date literal in quotes ("1990-05-15"), a cell reference (A2), or a function such as TODAY() or DATE(1990,5,15).
end_dateRequiredThe later date. Must be on or after start_date or DATEDIF returns #NUM!.
unitRequiredA text code that selects the unit: "Y", "M", "D", "YM", "MD", or "YD". Case does not matter, but uppercase is conventional.
!
The unit must be in quotes

Writing =DATEDIF(A2, TODAY(), Y) makes Excel look for a defined name called Y. It fails with #NAME?. Always wrap the unit code in double quotes.

!
Order matters — #NUM! if reversed

Unlike subtraction, DATEDIF does not accept negative intervals. If start_date is later than end_date, the formula stops with #NUM!. This is the single most common DATEDIF error.

03

The Six Unit Codes

The unit code is what makes DATEDIF flexible. Each code tells the function how to slice the interval between the two dates.

All six DATEDIF units
UnitReturnsTypical use
"Y"Complete years between the datesAge, employee tenure in whole years
"M"Complete months between the datesTotal months of a subscription or loan
"D"Total days between the datesSimple day counts, project length
"YM"Months left over after whole yearsAge in “X years, Y months” format
"MD"Days left over after whole months and yearsAge in “X years, Y months, Z days” — use with care
"YD"Days left over after whole yearsDay-of-year count between dates with same month/day

Worked example — all six at once

Start date 1990-05-15, end date 2025-03-10. Here is what every unit returns:

All six unitsSheet1
A
Unit
B
Formula
C
Result
1“Y”=DATEDIF(“1990-05-15″,”2025-03-10″,”Y”)34
2“M”=DATEDIF(“1990-05-15″,”2025-03-10″,”M”)417
3“D”=DATEDIF(“1990-05-15″,”2025-03-10″,”D”)12,718
4“YM”=DATEDIF(“1990-05-15″,”2025-03-10″,”YM”)9
5“MD”=DATEDIF(“1990-05-15″,”2025-03-10″,”MD”)23 (fragile)
6“YD”=DATEDIF(“1990-05-15″,”2025-03-10″,”YD”)299 (fragile)
How to read it: 34 years, 9 months, and 23 days have elapsed. Total months is 417 (= 34×12 + 9). Total days is 12,718. The "MD" and "YD" units are marked fragile because they can give different answers on different Excel builds.
!
“MD” is documented as unreliable

Microsoft’s own documentation states that the "MD" argument “may result in a negative number, a zero, or an inaccurate result”. Do not use it for payroll, billing, or compliance calculations. Build the day remainder yourself from "YM" and the calendar if you need accuracy.

04

Real-World Examples

These are the patterns that appear in real workbooks. Each example includes the spreadsheet layout and the exact formula for each cell.

Example 1 — Age in years, months, and days

The classic use: calculate an age today from a birthdate, and format it as “X years, Y months, Z days”.

Age CalculatorAge.xlsx
A
Name
B
Birthdate
C
Years
D
Months
E
Days
F
Age string
2Sara Ali1990-05-153492334 years, 9 months, 23 days
3Ravi Kumar2001-11-03234723 years, 4 months, 7 days
4Lena Fischer1985-02-204001840 years, 0 months, 18 days
Formulas: C2 → =DATEDIF(B2,TODAY(),"Y") · D2 → =DATEDIF(B2,TODAY(),"YM") · E2 → =DATEDIF(B2,TODAY(),"MD") · F2 → =C2&" years, "&D2&" months, "&E2&" days"
Age formulas
' Complete years
=DATEDIF(B2, TODAY(), "Y")

' Remaining months after whole years
=DATEDIF(B2, TODAY(), "YM")

' Remaining days (fragile — see note)
=DATEDIF(B2, TODAY(), "MD")

' All three, concatenated into one string
=DATEDIF(B2,TODAY(),"Y") & " years, "
& DATEDIF(B2,TODAY(),"YM") & " months, "
& DATEDIF(B2,TODAY(),"MD") & " days"

Example 2 — Employee tenure report

HR wants tenure broken into years and months, with a “milestone” flag for anyone past 5 years.

Employee TenureHR.xlsx
A
Employee
B
Start Date
C
Years
D
Months
E
Tenure
F
Milestone
2Priya Shah2019-03-11606 years, 0 months5+ yrs
3Marcus Lee2022-08-01373 years, 7 months—
4Elena Novak2020-01-15626 years, 2 months5+ yrs
Formulas: C2 → =DATEDIF(B2,TODAY(),"Y") · D2 → =DATEDIF(B2,TODAY(),"YM") · E2 → =C2&" years, "&D2&" months" · F2 → =IF(C2>=5,"5+ yrs","—")

Example 3 — Project duration tracker

Project managers want to know how long each project ran, in total days and in months.

Project DurationProjects.xlsx
A
Project
B
Start
C
End
D
Days
E
Months
F
Status
2Website Redesign2025-01-062025-04-301143Complete
3CRM Migration2025-02-172026-01-3134811Complete
4Data Warehouse2025-09-012026-06-303029In progress
Formulas: D2 → =DATEDIF(B2,C2,"D") · E2 → =DATEDIF(B2,C2,"M") · F2 → =IF(C2<TODAY(),"Complete","In progress")

Example 4 — Warranty countdown

Retail wants to know how many days of warranty remain on each product sold.

Warranty TrackerWarranty.xlsx
A
Product
B
Sold
C
Warranty (mo)
D
Expires
E
Days left
F
Status
2Laptop Pro 142025-03-10242027-03-10365Active
3Monitor 27″2024-06-15122025-06-15-97Expired
4Keyboard MX2025-08-01362028-08-01874Active
Formulas: D2 → =EDATE(B2,C2) · E2 → =IF(D2>=TODAY(),DATEDIF(TODAY(),D2,"D"),-DATEDIF(D2,TODAY(),"D")) · F2 → =IF(D2>=TODAY(),"Active","Expired")
✓
How to handle a negative interval

DATEDIF refuses to count backwards, so wrap it in an IF that swaps the dates when the target has already passed. That produces a signed day count that works in both directions.

Example 5 — Subscription billing cycles

SaaS finance teams count how many complete billing cycles have elapsed since a customer signed up.

Subscription CyclesSaaS.xlsx
A
Customer
B
Signed Up
C
Months
D
Cycles Billed
E
Next Invoice
2Acme Corp2023-04-0126262025-06-01
3Globex Inc2024-11-15772025-06-15
4Initech2025-01-01552025-06-01
Formulas: C2 → =DATEDIF(B2,TODAY(),"M") · D2 → =C2 · E2 → =EDATE(B2,C2+1)
05

DATEDIF vs Other Date Functions

DATEDIF is not the only way to measure a date interval. Four other functions cover overlapping ground, and one of them may be a better fit for your case.

Choosing the right date-difference function
FunctionReturnsUse when
DATEDIFComplete years, months, or daysYou need “X years, Y months, Z days” or any complete-unit count
YEARFRACFractional years (e.g. 2.75)You need a decimal year for prorating interest or amortization
DAYSPlain day countYou just want the number of days — simpler and more reliable than "D"
NETWORKDAYSBusiness days onlyYou need to exclude weekends and holidays
EDATEA date n months awayYou need to shift a date forward or backward by whole months
DATEDIF for a plain day count
=DATEDIF(A2,B2,"D")
Returns a day count but fails with #NUM! if B2 is earlier than A2.
DAYS for a plain day count
=DAYS(B2,A2)
Handles negative intervals, is documented, and autocompletes. Prefer this.
Side-by-side equivalents
' Total days — use DAYS instead of DATEDIF "D"
=DAYS(B2, A2)

' Total months — no equivalent, keep DATEDIF "M"
=DATEDIF(A2, B2, "M")

' Complete years — no equivalent, keep DATEDIF "Y"
=DATEDIF(A2, B2, "Y")

' Fractional years — use YEARFRAC for decimals
=YEARFRAC(A2, B2)

' Business days only — use NETWORKDAYS
=NETWORKDAYS(A2, B2)
i
YEARFRAC is not a replacement for DATEDIF “Y”

YEARFRAC("1990-05-15","2025-03-10") returns roughly 34.82, not 34. If you need whole years of age, use DATEDIF. If you need the fraction of a year for a financial calculation, use YEARFRAC.

06

Common Errors and How to Fix Them

Error reference — cause and fix
ErrorWhat it meansFix
#NUM!start_date is later than end_dateSwap the arguments or guard with IF
#NAME?Unit code is unquoted, or the function name is misspelledWrite "Y", not Y
#VALUE!One of the dates is text that Excel cannot parseConvert with DATEVALUE or DATE
Wrong result, no errorUsing "MD" or "YD"Avoid those units, or verify against a manual count
Formula does not autocompleteDATEDIF is not in the function wizardType the full name — this is expected
Defensive DATEDIF patterns
' Guard against reversed dates
=IF(B2>=A2, DATEDIF(A2,B2,"Y"), "Check dates")

' Wrap in IFERROR for imported data
=IFERROR(DATEDIF(A2,B2,"M"), 0)

' Convert text dates before using DATEDIF
=DATEDIF(DATEVALUE(A2), DATEVALUE(B2), "D")

' Build dates from parts
=DATEDIF(DATE(1990,5,15), TODAY(), "Y")
07

Practice Exam — 5 Questions

Type your answer in the box and click Check. Answers are case-insensitive and ignore extra spaces.

  1. Q1. What does =DATEDIF("1990-05-15","2025-03-10","Y") return?
  2. Q2. What does =DATEDIF("1990-05-15","2025-03-10","M") return?
  3. Q3. What does =DATEDIF("1990-05-15","2025-03-10","YM") return?
  4. Q4. What error does =DATEDIF("2025-03-10","1990-05-15","Y") return? (Include the error symbol.)
  5. Q5. Which unit code returns the number of days between two dates ignoring years? (Answer with the two-letter code.)
Score: 0 / 5
✓
Stuck on a question?

Work through the worked example tables above — every answer is derivable from the six-unit table and the error reference.

08

Best Practices

DATEDIF is easy to use badly. These habits keep your date formulas correct and readable.

01

Check the order of dates

Always confirm start_date <= end_date, or guard with IF. Reversed dates return #NUM!.

02

Avoid the “MD” unit

Microsoft documents it as potentially inaccurate. Build the day remainder another way if accuracy matters.

03

Prefer DAYS for total days

=DAYS(end,start) is documented, handles negatives, and is easier to audit than DATEDIF(...,"D").

04

Use YEARFRAC for decimals

For prorated interest or amortization, YEARFRAC is the right tool, not DATEDIF.

05

Store dates as real dates

A text “1990-05-15” causes #VALUE!. Convert with DATEVALUE or use DATE.

06

Wrap with IFERROR on imports

Imported CSVs often contain blanks and text in date columns. IFERROR keeps the report clean.

07

Use TODAY() for live values

For “age as of today” reports, TODAY() is the right end date — but note it recalculates every time the file opens.

08

Document the units in the header

“Years”, “Months”, “Days” above each column makes the report readable and prevents confusion with total months.

09

Frequently Asked Questions

What is the DATEDIF function in Excel?

DATEDIF returns the difference between two dates in complete years, months, or days. Its syntax is =DATEDIF(start_date, end_date, unit). It is a hidden compatibility function carried over from Lotus 1-2-3.

Why doesn’t DATEDIF appear in Excel’s autocomplete?

Microsoft keeps DATEDIF for backwards compatibility but never added it to the function wizard or autocomplete list. You have to type the full name from memory.

What units does DATEDIF accept?

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

Why does DATEDIF return #NUM!?

#NUM! appears when start_date is later than end_date. DATEDIF only accepts intervals going forward in time. Swap the arguments or guard with IF.

Is DATEDIF reliable?

Mostly yes, with one exception: the "MD" unit is documented by Microsoft as potentially inaccurate and should be avoided for anything mission-critical. The "Y", "M", "D", and "YM" units are reliable.

How do I calculate age in Excel?

Use =DATEDIF(birthdate, TODAY(), "Y") to get complete years of age. For “X years, Y months, Z days”, concatenate three DATEDIF calls with different units.

How do I get years, months, and days in one cell?

Concatenate three DATEDIF calls: =DATEDIF(A2,TODAY(),"Y")&" years, "&DATEDIF(A2,TODAY(),"YM")&" months, "&DATEDIF(A2,TODAY(),"MD")&" days". Note the "MD" caveat above.

What replaced DATEDIF?

Nothing replaced it. YEARFRAC, DAYS, and NETWORKDAYS handle related tasks, but no other function produces the same complete-unit output that "Y", "M", and "YM" produce.

Does DATEDIF work with times?

No. DATEDIF ignores the time component entirely and works only with the date portion. For time differences, subtract the two values directly and format the result as [h]:mm.

Is DATEDIF case-sensitive?

No. "y", "Y", "d", and "D" all work identically. Uppercase is the convention for readability.

10

Key Takeaways

  • DATEDIF returns the interval between two dates in complete units.
  • The syntax is =DATEDIF(start_date, end_date, unit) — all three arguments are required.
  • Six units: "Y", "M", "D", "YM", "MD", "YD".
  • It is a hidden function — no autocomplete, no tooltip, no wizard entry.
  • Reversed dates return #NUM!; guard with IF.
  • The "MD" unit is documented as unreliable — avoid it for anything important.
  • Use DAYS instead of "D" for a plain total day count.
  • Use YEARFRAC instead of DATEDIF when you need fractional years.
  • Dates must be real date values, not text — otherwise #VALUE!.
  • For live age reports, TODAY() as the end date recalculates on every open.
  • Chain "Y", "YM", and "MD" to build an “X years, Y months, Z days” string.
  • Wrap DATEDIF in IFERROR when working with imported or user-entered dates.
11

What to Learn Next

DATEDIF is one member of Excel’s date and logical family. The natural next steps are the functions that pair with it in real workbooks.

Start with the companion date functions: yearfrac-function, days-function, and networkdays-function.

Then connect them to the logical tools: if-function, iferror-function, and ifs-function.

Inar Learn
Inar Learnhttps://inarlearn.com
Inar Learn is an innovative online learning platform offering high-quality courses, tutorials, and resources to help learners gain practical skills and grow their knowledge.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here