WorkbookLogic
FunctionDate and timeintermediateDATEDIFIF

DATEDIF Function

By WorkbookLogic

The Excel DATEDIF function returns complete years, months, days, or remainder components between two dates using a selected unit code.

ExcelLast reviewed Sep 11, 2026
datedif-function-v1.0.0.xlsx
Excel DATEDIF Function
DATEDIF counts complete date intervals using a selected unit code.
Source cases, editableDATEDIF examples
ScenarioStart dateEnd dateUnitMeaningExampleFormula syntaxResult
Complete yearsAug 15, 2020Aug 15, 2026YWhole yearsComplete years=DATEDIF(B12,C12,D12)6
Complete monthsJan 15, 2026Aug 15, 2026MWhole monthsComplete months=DATEDIF(B13,C13,D13)7
Elapsed daysJan 1, 2026Jan 31, 2026DCalendar daysElapsed days=DATEDIF(B14,C14,D14)30
Months after yearsMay 10, 2020Aug 15, 2026YMRemainder monthsMonths after years=DATEDIF(B15,C15,D15)3
Days after monthsJul 20, 2026Aug 15, 2026MDRemainder daysDays 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 anniversariesOK
January 1 through January 31 has 30 elapsed daysOK

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

"y"

Complete years.

"m"

Complete months.

"d"

Total days.

"ym"

Remaining months after complete years.

"yd"

Remaining days after complete years.

"md"

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 #NUM!.

Invalid date input

Returns an error.

Unit case

Unit codes are not case-sensitive.

"d"

Equivalent to the total elapsed day count.

"md" and some remainder cases

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.