Function · Date and time

Excel DATEDIF function

The Excel DATEDIF function returns complete years, months, or days between two dates. From January 15, 2024 to July 4, 2026 is 2 years, 29 months, and 901 days. Excel leaves it out of the function list.

All current Excel versions, though it is undocumented in the Insert Function list. Also in Google Sheets.

Syntax =DATEDIF(start_date, end_date, unit)

DATEDIF
=DATEDIF(DATE(2024,1,15),DATE(2026,7,4),"Y")

Arguments

NameRequiredWhat to pass
start_dateRequiredThe earlier date.
end_dateRequiredThe later date. If it is earlier than the start, the result is #NUM!.
unitRequired"Y" complete years, "M" complete months, "D" days, "YM" months after stripping whole years, "YD" days after stripping whole years, "MD" days after stripping whole months.

Examples

Complete years from January 15, 2024 to July 4, 2026

=DATEDIF(DATE(2024,1,15),DATE(2026,7,4),"Y")

Result 2

=DATEDIF(B1,B2,"Y")B3
Age
AB
1Start1/15/2024
2End7/4/2026
3Whole years2
A picture of the sheet, not a live calculator. The unit is the letter Y, in quotes. Excel may not offer DATEDIF in the function picker. Type it anyway.

DATEDIF measures a completed interval. From January 15, 2024 to July 4, 2026 the completed years are 2, because July 4 has not yet reached January 15 of a third year. The completed months are 29. Strip the 2 years off and 5 months remain, which is the YM unit. The day count, D, is 901, the same difference DAYS would return.

Excel still calculates DATEDIF and still hides it in the Insert Function dialog, so a misspelled unit looks like a broken name. The MD unit, days ignoring months, is the one to avoid. It has known wrong results when the dates sit near the ends of months of different lengths. Y, M, D, and YM are the units that match this example. If the end date is earlier than the start, the result is #NUM!, not a negative.