Excel functions · Dates

DATEDIF function in Excel

DATEDIF calculates the number of whole years, months or days between two dates, which makes it the usual way to work out age or length of service. It's a hidden function: Excel doesn't suggest it as you type, so you enter it in full, and the unit you choose ("Y", "M", "D" and others) decides what it counts.

Last reviewed

Syntax

=DATEDIF(start_date, end_date, unit)
start_daterequired
The earlier date.
end_daterequired
The later date. It must not be before start_date.
unitrequired
What to count, in quotes: "Y" whole years, "M" whole months, "D" days, "YM" months left after whole years, "YD" days left after whole years, "MD" days left after whole months.
  • Use TODAY() as end_date for an age or tenure that stays current.
  • Microsoft's own page warns that the "MD" unit can return a negative number, a zero or an inaccurate result; avoid it.
  • For plain day counts, end_date - start_date gives the same as "D".

Which versions have DATEDIF

Every current Excel version: Microsoft 365, Excel for the web, Excel 2024, 2021, 2019 and 2016, on Windows and Mac.

DATEDIF works in every Excel version, but it isn't listed in Insert Function or formula AutoComplete, so you type it in full. Microsoft keeps it for compatibility with Lotus 1-2-3.

DATEDIF availability by Excel version
VersionHas it
Microsoft 365 (Windows and Mac)Yes
Excel for the webYes
Excel 2024Yes
Excel 2021Yes
Excel 2019Yes
Excel 2016Yes

Google Sheets

Google Sheets has DATEDIF, documented and listed like any other function, with the same units.

Examples

The examples use this sample sheet.

Employee dates (A1:C2)
RowABC
1EmployeeStart dateReview date
2Nadia2019-03-152026-11-20
  1. 1.Whole years of service

    =DATEDIF(B2, C2, "Y")

    Result: 7

    From 15 March 2019 to 20 November 2026 is 7 full years; the 8th isn't complete until March 2027.

  2. 2.Total whole months

    =DATEDIF(B2, C2, "M")

    Result: 92

    7 years (84 months) plus 8 months, from 15 March to 15 November.

  3. 3.Years and months as text

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

    Result: 7 years, 8 months

    "YM" counts the months left over after the whole years.

Common errors and fixes

DATEDIF errors, causes and fixes
ErrorWhy it happensFix
#NUM!start_date is after end_date.Swap the dates, or wrap the formula in IF to check which is earlier.
#VALUE!A date is text that Excel can't read as a date.Convert it with DATEVALUE, or re-enter it as a real date.
#NUM! from a typo in unitunit isn't one of Y, M, D, YM, YD or MD, or is missing its quotes.Put the unit in quotes: "Y".

Do it with GPTExcel

Skip writing DATEDIF by hand

Upload your Excel or CSV file to Chat and ask in plain English. GPTExcel writes the formula for your file and your version of Excel or Google Sheets.

your-file.xlsx

Work out each employee's tenure in years and months as of today.

Done. I used DATEDIF on your sheet and checked the results against your data.

your-file-updated.xlsxYour original stays unchanged
  • Written for your platform and version
  • Checked against your actual data
  • Newest functions looked up in official docs
Try it free Formula Generator

Free plan, no credit card.

DATEDIF questions

Why can't I find DATEDIF in Excel?
Excel doesn't list DATEDIF in Insert Function or suggest it as you type, but it works in every version. Type it in full, such as =DATEDIF(B2, C2, "Y").
How do I calculate age in Excel?
Use =DATEDIF(birth_date, TODAY(), "Y"). It counts only full years, so the age goes up on the birthday.
Does DATEDIF work in Google Sheets?
Yes. Google Sheets documents DATEDIF in its function list, with the same units as Excel.

Skip the formula hunt

Upload a spreadsheet and ask in plain English. Free plan, no credit card.

Start free