Excel function

DATEDIFfunction

Counts the complete years, months or days between two dates. Use it for ages and lengths of service.

All versions
=DATEDIF(DATE(2001,6,15), DATE(2026,11,24), "Y")
Clicking a date sets

June 2001

Sun
Mon
Tue
Wed
Thu
Fri
Sat

⋯November 2026

Sun
Mon
Tue
Wed
Thu
Fri
Sat

Click a date on the calendar to change start_date. Change the end date below to 2026-06-14 and then 2026-06-15. A year is only added once the start month and day (June 15) is reached, so 24 becomes 25. Try breaking it on purpose to see the errors.

Result

25

start_date
Jun 15, 2001 (Fri)

The first date of the period. For an age, the date of birth.

end_date
Nov 24, 2026 (Tue)

The last date of the period. Earlier than start_date gives #NUM!.

unit

What to count. In a formula, write it in quotes, like "Y".

What is the DATEDIF function?

=DATEDIF(start_date, end_date, unit)

DATEDIF counts how many years, months or days lie between two dates. It is widely used for "complete" periods such as ages, years of service and contract lengths.

According to Microsoft, DATEDIF is kept to support old workbooks from Lotus 1-2-3, so it does not appear in the function list or AutoComplete. Typing the name directly works normally. Microsoft does not recommend the "MD" unit because it can give wrong results, so this playground leaves it out.

Arguments

start_date
The first date of the period, such as a date of birth or start date.
end_date
The last date of the period. Use TODAY() to measure up to today. Earlier than start_date gives #NUM!.
unit
"Y" complete years, "M" complete months, "D" days, "YM" months left after whole years, "YD" days ignoring the year. Write it in quotes.

DATEDIF examples

  1. Example 1. Age

    =DATEDIF(B2, TODAY(), "Y")

    Complete years from the date of birth in B2 to today. The age goes up only after the birthday.

  2. Example 2. Service as "x years y months"

    =DATEDIF(B2, TODAY(), "Y") & " years " & DATEDIF(B2, TODAY(), "YM") & " months"

    Joins the years and the remaining months.

  3. Example 3. Example from Microsoft

    =DATEDIF("2001-06-01", "2002-08-15", "YD")

    Ignoring the year, June 1 to August 15 is 75 days.

Common mistakes

FAQ

Why is it not in the function list?
It is kept for compatibility, so it does not appear in AutoComplete or the Insert Function dialog. Type =DATEDIF( directly.
Just need the number of days?
=end_date-start_date or DAYS(end_date, start_date) is enough.