DATEDIF Function
The Excel DATEDIF function returns complete years, months, days, or remainder components between two dates using a selected unit code.
| Excel DATEDIF Function | ||||||||
| DATEDIF counts complete date intervals using a selected unit code. | ||||||||
| Source cases, editable | DATEDIF examples | |||||||
| Scenario | Start date | End date | Unit | Meaning | Example | Formula syntax | Result | |
| Complete years | Aug 15, 2020 | Aug 15, 2026 | Y | Whole years | Complete years | =DATEDIF(B12,C12,D12) | 6 | |
| Complete months | Jan 15, 2026 | Aug 15, 2026 | M | Whole months | Complete months | =DATEDIF(B13,C13,D13) | 7 | |
| Elapsed days | Jan 1, 2026 | Jan 31, 2026 | D | Calendar days | Elapsed days | =DATEDIF(B14,C14,D14) | 30 | |
| Months after years | May 10, 2020 | Aug 15, 2026 | YM | Remainder months | Months after years | =DATEDIF(B15,C15,D15) | 3 | |
| Days after months | Jul 20, 2026 | Aug 15, 2026 | MD | Remainder days | Days after months | =DATEDIF(B16,C16,D16) | 26 | |
| How DATEDIF behaves | ||||||||
| DATEDIF counts complete intervals; a partial year or month is not rounded up. | ||||||||
| Y, M, and D return total complete units, while YM and MD return remainder components. | ||||||||
| The start date must not be later than the end date. | ||||||||
| Reliability checks | ||||||||
| Six complete years are returned for matching anniversaries | OK | |||||||
| January 1 through January 31 has 30 elapsed days | OK | |||||||
Overview
The Excel DATEDIF function measures the interval between two dates in complete years, complete months, total days, or remainder components. It always returns a whole number and truncates incomplete intervals.
Quick reference
Syntax: =DATEDIF(start_date, end_date, unit)
Returns: A whole-number interval count determined by the selected unit code. (number)
Arguments:
start_date(required) — The earlier date in the interval.end_date(required) — The later date in the interval.unit(required) — A text code selecting complete years, months, days, or a remainder component.
All three arguments are required. The start date must not be later than the end date, and the unit is supplied as a quoted code that controls whether the result is a complete interval or remainder component.
Common uses
- Calculate age in complete years.
- Measure employee or customer tenure.
- Count complete months in a contract.
- Break an elapsed period into years, months, and days.
Calculations
DATEDIF counts completed intervals from start_date to end_date. A span of 6 years and 11 months returns 6 with unit "y", because the seventh year is incomplete.
Unit | Result |
|---|---|
| Complete years. |
| Complete months. |
| Total days. |
| Remaining months after complete years. |
| Remaining days after complete years. |
| Remaining days after complete months. |
The start date must not be later than the end date. DATEDIF is a legacy compatibility function and may not appear in formula autocomplete, even though Excel evaluates it.
Function behavior
Situation | Behavior |
|---|---|
Partial interval | Truncated rather than rounded. |
Reversed dates | Returns |
Invalid date input | Returns an error. |
Unit case | Unit codes are not case-sensitive. |
| Equivalent to the total elapsed day count. |
| Can produce unintuitive or inaccurate results near month ends and leap boundaries. |
Formula assistance | May not appear in autocomplete or the function wizard. |
Common errors
Reversing start and end dates
What happens:
DATEDIF returns #NUM!.
Better approach:
Validate the date order or intentionally handle reversed inputs before calling DATEDIF.
Treating the output as a rounded duration
What happens:
An incomplete year or month is expected to round up, but DATEDIF truncates it.
Better approach:
Use a fractional method such as YEARFRAC when the business definition requires proportions.
Relying on the MD unit without testing boundaries
What happens:
Month-end and leap-date combinations can yield surprising results.
Better approach:
Test the exact date patterns or use a more explicit date-arithmetic formula.
Example
Example 1 — Complete Years
=DATEDIF(B12,C12,D12)
From 15-Aug-2020 to 15-Aug-2026, unit "y" returns 6.
Example 2 — Complete Months
=DATEDIF(B13,C13,D13)
The selected unit counts only fully completed calendar-month intervals.
Example 3 — Total Days
=DATEDIF(B15,C15,D15)
From January 1 to January 31, unit "d" returns 30.
Example workbook
The workbook contains a DATEDIF Example sheet with five editable start dates, end dates, and unit codes. Live formulas demonstrate complete years, months, days, and remainder behavior, while two checks confirm the six-year anniversary and the 30-day January interval. A Notes sheet explains unit codes and date ordering.
Key takeaway
Choose the unit deliberately and read the result as complete intervals; test remainder units carefully around month-end and leap-date boundaries.