DATEDIF Function
Returns the difference between two dates in years, months, or days.
Syntax
Parameters
| Parameter | Description | Required |
|---|---|---|
| start_date | The earlier date. Must be less than or equal to end_date. | Required |
| end_date | The later date. | Required |
| unit | Text code: "Y" full years, "M" full months, "D" days, "MD" days excluding months/years, "YM" months excluding years, "YD" days excluding years. | Required |
Basic Example
Full years between two dates
=DATEDIF(DATE(2020, 1, 1), DATE(2024, 6, 1), "Y")From Jan 1 2020 to Jun 1 2024 there are 4 complete years (the sixth month is not yet reached).
Advanced Examples
Example 1: Total complete months
Measuring tenure in monthsUnit "M" counts full months
=DATEDIF(DATE(2020, 1, 1), DATE(2024, 6, 1), "M")Example 2: Remaining months after full years
Age in years and monthsUnit "YM" ignores the year count
=DATEDIF(DATE(2021, 3, 15), DATE(2024, 7, 20), "YM")How DATEDIF Works
DATEDIF compares the two date serials. For Y/M it counts whole years or months, while the remainder units (YM, YD, MD) compute what is left after stripping the larger unit. It is an undocumented compatibility function carried over from Lotus 1-2-3.
Important Notes & Limitations
It is undocumented, so it does not appear in formula autocomplete or help.
start_date must be less than or equal to end_date, otherwise it returns #NUM!.
The "MD" unit has a long-standing Microsoft bug that can return incorrect or negative values in some date combinations; prefer "D" or compute days manually when precision matters.
Common Errors & Fixes
#NUM!start_date is later than end_date, or the unit text is invalid.Fix: Ensure start_date <= end_date and use one of the six valid unit codes.
#VALUE!A non-date value or an unrecognized unit code was supplied.Fix: Pass real date serials and a valid unit string in quotes.
Download Practice File
DATEDIF
datedifPractice DATEDIF with Real Data
Download a sample CSV file with pre-populated data and practice exercises for the DATEDIF function. Works in both Excel and Google Sheets.
File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps