Calculate the difference between two dates in years, months, or days.
Syntax
DATEDIF(start_date, end_date, unit)Arguments
start_daterequired
The earlier date.
end_daterequired
The later date.
unitrequired
"Y", "M", or "D" (also "YM", "MD", "YD").
DATEDIF returns the elapsed time between two dates in the unit you choose — "Y" for whole years, "M" for months, "D" for days. It's ideal for age, tenure, and duration calculations. The function is hidden in Excel's menus but fully supported.
=DATEDIF(A2, TODAY(), "Y")→7Returns whole years between a hire date and today.
=DATEDIF(A2, B2, "D")→146Returns the number of days between two dates.
Order the dates
Put the earlier date first or DATEDIF returns an error.
Pick the unit
Use "Y", "M", or "D" depending on the granularity you need.
It's a legacy compatibility function Microsoft keeps hidden, but it works in all modern versions when typed manually.