fxExcelReps
← All functions 📅 Date & time · Intermediate

DATEDIF Age and time between two dates in years, months or days.

How to use DATEDIF in Excel

DATEDIF calculates the number of complete years, months or days between two dates — the standard way to get age or length of service. It's a hidden function: Excel doesn't suggest it as you type, but it works in every version.

Syntax

=DATEDIF(start_date, end_date, "Y" | "M" | "D")

start_dateThe earlier date.
end_dateThe later date.
unit"Y" full years, "M" full months, "D" days, "YM" months after full years, "MD" days after full months.

Examples

=DATEDIF(B2, TODAY(), "Y")Age in years.
=DATEDIF(B2, TODAY(), "Y")&" y "&DATEDIF(B2, TODAY(), "YM")&" m""35 y 4 m".
=DATEDIF(C2, D2, "M")Full months between two dates.

Age and length of service

"Y" counts complete years, so a birthday or work anniversary that hasn't happened yet this year isn't counted. That's exactly how age works.

=DATEDIF(B2, TODAY(), "Y")Age today from the date of birth in B2.
=DATEDIF(C2, TODAY(), "Y")&" years, "&DATEDIF(C2, TODAY(), "YM")&" months"Service like "7 years, 4 months".

Loan and deposit terms in months

"M" counts complete months between two dates: useful for the remaining term of a loan or how long a deposit has run.

=DATEDIF(TODAY(), D2, "M")Months left until the maturity date in D2.
=DATEDIF(B2, C2, "M")/12The term in years, with decimals.

Days, and when to just subtract

For days you don't need DATEDIF: dates are numbers, so the end minus the start already gives days.

=C2-B2Days between two dates (format the cell as a number).
=DATEDIF(B2, C2, "YD")Days since the last anniversary, ignoring the years.

Common mistakes

#NUM! error
The start date is after the end date — swap them.
"MD" gives odd results
Microsoft documents a known issue with "MD"; avoid it for important calculations.

Frequently asked questions

Why can't I find DATEDIF in Excel?

It's a hidden function, kept for compatibility with old spreadsheets. Excel doesn't suggest it as you type and it has no help in the Insert Function window, but it works in every version.

Why does DATEDIF return #NUM!?

The start date is later than the end date. Swap them, or wrap the formula: =IF(B2>C2, "", DATEDIF(B2, C2, "Y")).

What do Y, M, D, YM, YD and MD mean?

Y complete years, M complete months, D days. YM months left over after the years, YD days left over after the years, MD days left over after the months (MD can give odd results, so avoid it).

How do I calculate age in Excel?

=DATEDIF(B2, TODAY(), "Y") with the date of birth in B2. Practise date maths with TODAY and YEAR, MONTH, DAY.

Available in: All versions of Excel, Excel for the web, Google Sheets

Related functions

TODAYDATEYEAR, MONTH, DAYNETWORKDAYS

↑ Practise DATEDIF in the sheet above