DATEDIF Function in Microsoft Excel: Syntax, Examples & Compatibility
Learn how to measure completed years or days between two dates without counting partial anniversaries as full years in Microsoft Excel. Includes syntax, two verified-by-reasoning results, troubleshooting and portability notes.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: DATEDIF measures a date interval in a selected unit, including complete years, complete months or elapsed days. Microsoft retains it for older Lotus 1-2-3 workbooks and warns about incorrect results in some scenarios, particularly the MD unit.
Availability and version history
- Introduced: Introduction version not established by the official history reviewed.
- Availability: Official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016, Windows SharePoint Services 3.0.
- Checked: October 14, 2026; official DATEDIF reference. Documentation check, not a new native test; existing example-verification notes retain their scope.
Syntax and input setup
=DATEDIF(start_date, end_date, unit)
Examples use English function names and comma separators. Enter formula inputs exactly as shown, keep outputs outside the input cells, and use the specified date or numeric output format.
All three arguments are required. Use ordered dates and a quoted unit code. Format the answer as Number rather than Date. Microsoft’s compatibility explanation is not a retirement notice: the current reference still documents the function, with the limitations described below.
Two original worked controls
=DATEDIF(DATE(2020,1,1),DATE(2025,1,1),"Y")
=DATEDIF(DATE(2025,1,10),DATE(2025,2,9),"D")
Expected results are 5 complete years and 30 elapsed days. The first interval reaches the fifth anniversary exactly. The second measures the calendar difference rather than counting both endpoints as full attendance dates.
For a plain signed day difference, ordinary end-minus-start subtraction or DAYS can be clearer. DAYS puts the end date first, whereas DATEDIF puts the start date first; do not transfer arguments unchanged.
Unit meanings and the MD warning
| Unit | Documented purpose |
|---|---|
"Y" |
Complete years |
"M" |
Complete months |
"D" |
Elapsed days |
"YM" |
Month component with years ignored |
"YD" |
Day difference with years ignored |
"MD" |
Day component with months and years ignored; Microsoft recommends against it |
These codes are not interchangeable with dividing days by 365 or 30. Microsoft warns that MD can produce negative, zero or inaccurate results. This guide does not offer MD as a dependable residual-days calculation.
The YD and YM descriptions also do not establish every leap-day or unequal-day-of-month boundary here. The component controls below use an ordinary equal-day-of-month interval so they do not pretend to settle those edges.
Advanced example: inspect the day before and on an anniversary
=DATEDIF(DATE(2020,6,15),DATE(2026,6,14),"Y")
=DATEDIF(DATE(2020,6,15),DATE(2026,6,15),"Y")
Expected results are 5 and 6. Merely subtracting 2020 from 2026 gives six in both cases, but the first interval has not yet completed its sixth anniversary.
For this non-leap anniversary, the following day June 16 also gives six. These simple adjacent dates make the meaning of completed years visible without relying on a changing TODAY value.
Advanced example: inspect completed months
=DATEDIF(DATE(2026,1,15),DATE(2026,2,14),"M")
=DATEDIF(DATE(2026,1,15),DATE(2026,2,15),"M")
Expected results are 0 and 1. The first interval falls one day short of the monthly anniversary. A raw difference between the month numbers gives one in both cases and therefore answers a different question.
For January 15 through March 15, 2026, the expected complete-month result is 2, while elapsed days are 59. Dividing 59 by 30 gives approximately 1.966666667, illustrating why a fixed-length month assumption is unsuitable for this unit.
Advanced example: years, total months and residual months
For May 15, 2020 through August 15, 2026:
=DATEDIF(DATE(2020,5,15),DATE(2026,8,15),"Y")
=DATEDIF(DATE(2020,5,15),DATE(2026,8,15),"M")
=DATEDIF(DATE(2020,5,15),DATE(2026,8,15),"YM")
Expected results are 6, 75 and 3. Total months are 6*12+3, so 75 must not be labeled “75 months in addition to six years.” It already includes those years.
On this equal-day-of-month fixture, taking MOD(75,12) independently gives the same residual three months. The YD control for the same start/end month-day pair has expected 92 days, the ordinary May 15 to August 15 calendar interval. No February 29 edge is certified by that example.
Advanced check: a days-since-month-start formula is narrower than MD
The vendor’s known-issues section illustrates subtracting the first day of the ending month from the end date. With end date March 10, 2026:
=DATE(2026,3,10)-DATE(2026,3,1)
Expected result: 9. This correctly measures days since March began, but it contains no start-date input. It therefore cannot be a universal replacement for residual days after completed months measured from an arbitrary start.
For example, January 20 to March 10, 2026 reaches one monthly anniversary on February 20; the ordinary February 20–March 10 difference is 18 days. The value nine answers the month-start question instead. Choose and document the required anniversary policy rather than copying a workaround beyond its scope.
Reversed dates, source precision and practical use
Microsoft explicitly documents #NUM! when start_date is later than end_date. The reversed original year interval therefore has that documented error rather than −5 complete years. If signed elapsed time is required, use a function whose signed rule matches the task.
The reference’s introductory subtraction tip reverses the wording of later-minus-earlier; the numerical day controls here use end minus start. That clarification does not remove the function’s separate warning about unsupported edge scenarios.
Use fixed as-of dates when verifying anniversary reports, and keep a clear policy for leap birthdays, month-end starts and incomplete periods. This guide does not certify every unit’s native boundary behavior or advise treating MD as safe after one successful sample.
Related guides and verification
YEAR in Microsoft Excel | YEAR in Google Sheets | DATE in Microsoft Excel | DATE in Google Sheets | NETWORKDAYS in Microsoft Excel | NETWORKDAYS in Google Sheets | editorial testing standards
The full manuscript and original worked formulas were reviewed on October 14, 2026. The approved availability/history section is unchanged. Expected results are independently calculated date/arithmetic models or explicitly documented rules, not native Excel output. Current-clock formulas have conditional rather than fixed outputs. Client-specific time-zone, mixed-type and boundary behavior is not inferred from another spreadsheet.