Date & time function

DATEDIF function

Counts the complete years, months or days between two dates — the classic way to calculate age or length of service.

Available in All versions of Excel (an undocumented legacy function: it does not appear in the formula autocomplete list, but it works when typed in full)

In every Excel versionWorks in Google Sheets

Syntax

DATEDIF(start_date, end_date, unit)
ArgumentWhat it means
start_dateRequiredThe earlier date, for example a birth date or hire date.
end_dateRequiredThe later date. Must not be before start_date.
unitRequiredA text code: "Y" complete years, "M" complete months, "D" days, "YM" months left over after whole years, "MD" days left over after whole months, "YD" days left over after whole years.

Returns: A whole number: the count of complete units between the two dates.

How DATEDIF works

DATEDIF answers questions like "how old is this employee?" or "how many full months has this customer been subscribed?". Subtracting two dates only gives days, and dividing by 365 goes wrong around birthdays and leap years. DATEDIF counts completed units the way people do: someone born on 14 July 1988 is still 37 on 13 July 2026 and turns 38 the next day.

The function is a leftover from Lotus 1-2-3 compatibility, so Excel hides it: you will not see it in the autocomplete list and there is no argument tooltip. Type it in full and it works in every version. The unit argument controls what you get back; combining "Y", "YM" and "MD" gives the familiar "7 years, 7 months, 9 days" format used in HR letters.

Note that end_date must be on or after start_date, otherwise you get #NUM!. For a decimal number of years (useful for pro-rating) use YEARFRAC instead.

Examples

1Employee age in whole years

C2fx=DATEDIF(B2,TODAY(),"Y")
ABC
1EmployeeBirth dateAge
2Maria Lopez1988-07-1438

Result: 38

If today is 2 Dec 2026, Maria has passed her 38th birthday (14 July 2026), so DATEDIF returns 38. The result updates every day because of TODAY.

2Length of service as years, months and days

C2fx=DATEDIF(A2,B2,"Y")&" yrs, "&DATEDIF(A2,B2,"YM")&" mths, "&DATEDIF(A2,B2,"MD")&" days"
ABC
1Hire dateEnd dateService
22019-04-232026-12-027 yrs, 7 mths, 9 days

Result: 7 yrs, 7 mths, 9 days

"Y" counts 7 full years (to 23 Apr 2026), "YM" adds the 7 full months after that (to 23 Nov 2026), and "MD" counts the 9 remaining days to 2 Dec 2026.

3Complete months of a subscription

D2fx=DATEDIF(B2,C2,"M")
ABCD
1CustomerStartEndMonths billed
2Northwind Ltd2025-11-152026-12-0212

Result: 12

From 15 Nov 2025 to 15 Nov 2026 is 12 complete months. The 17 days after that do not make a 13th complete month, so the answer is 12.

4Total days between two dates

C2fx=DATEDIF(A2,B2,"D")
ABC
1Hire dateEnd dateDays
22019-04-232026-12-022780

Result: 2780

"D" returns the plain day count, the same as =B2-A2 or =DAYS(B2,A2).

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#NUM!start_date is later than end_date, or the unit code is not one of the six valid codes.Swap the dates or wrap with IF(A2>B2, "", DATEDIF(...)); check the unit spelling.
#VALUE!One of the dates is text that Excel cannot read as a date.Convert it with DATEVALUE or DATE.

Tips

  • Avoid the "MD" unit when the start day is near the end of a month (29th–31st): Microsoft itself warns it can return a negative number or a wrong day count. Calculate leftover days with B2-EDATE(A2,DATEDIF(A2,B2,"M")) instead.
  • The unit is not case-sensitive: "y" and "Y" give the same result.
  • For anniversaries or birthdays coming up, "YD" gives the days since the last anniversary; subtract it from 365 for a rough countdown.

Questions

Why can't I find DATEDIF in the function list?

Microsoft keeps it only for compatibility, so it is hidden from autocomplete and the Insert Function dialog. Typing it in full works in every Excel version.

How do I calculate age in Excel?

Use =DATEDIF(birth_date, TODAY(), "Y"). It returns complete years and handles leap years and birthdays correctly.

Does DATEDIF count the end date?

No. It counts complete units between the dates, so 1 Jan to 2 Jan is 1 day, not 2.

Google Sheets

DATEDIF also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

DATEDIF in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishDATO.FORSKEL
DutchDATUMVERSCHIL
FinnishPVMERO
HungarianDÁTUMTÓLIG
ItalianDATA.DIFF
Norwegian (Bokmål)DATODIFF
PolishDATA.RÓŻNICA
Portuguese (Brazil)DATADIF
Portuguese (Portugal)DATADIF
RussianРАЗНДАТ
SpanishSIFECHA

Recipes that use DATEDIF