formulastreak

Dates function

DATEDIF function in Google Sheets and Excel

DATEDIF counts the complete years, months or days between two dates.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

DATEDIF(start_date, end_date, unit)

Arguments in [brackets] are optional. Google Sheets writes it DATEDIF(start_date, end_date, unit).

Example

=DATEDIF(C2,$H$2,"Y") reads: Count the complete years from Amara's start date in C2 to the As of date in $H$2.

Team directory · edit G2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultG2 = 7
ABCDEFGH
1NameDeptStartedBornSalaryLevelYears hereAs of
2Amara OseiSales15 Apr 20192 Aug 1990$58,0002730 Jun 2026
3Ben FischerSupport9 Jan 202321 Nov 1996$41,00013
4Lina ChenEngineering1 Sep 201614 Mar 1987$88,00049
5Diego AlvarezSales28 Jun 202130 Jun 1993$52,00025
6Eva NovakFinance12 Feb 20185 Dec 1985$74,00038
7Farid HaddadEngineering4 Mar 202419 Jan 1998$68,00022
8Grace KimSupport19 Oct 202027 Sep 1991$45,00025
9Hugo MartinFinance11 May 20158 Apr 1979$88,000411
10Ines VargaEngineering14 Nov 202228 Feb 1995$79,00033
11Kenji MoriSales25 Aug 202516 Jul 2000$39,00010

G2 shows 7: Amara started on 15 Apr 2019, and by 30 Jun 2026 she has completed 7 full years.

How the spreadsheet calculates it

Counts the whole years between C2 and $H$2.

  1. 1. DATEDIF: Counts the whole years between C2 and $H$2.
    • start = `C2`: the earlier date
    • end = `$H$2`: the later date
    • unit = `"Y"`: `"Y"` for completed years, `"M"` for months, `"D"` for days

More DATEDIF examples

  • =DATEDIF(D2,$H$2,"Y")Age in completed years from the date of birth in D2.
  • =DATEDIF(C2,$H$2,"M")Complete months of service: 86 for Amara.
  • =DATEDIF(C2,$H$2,"Y")&" years "&DATEDIF(C2,$H$2,"YM")&" months"Service as text: 7 years 2 months.
  • =DATEDIF(C2,TODAY(),"D")Days since the start date, counted to today.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Measure against a fixed "as of" date in reports so the numbers don't change every day.
  • Lock that date with $ before filling down.
  • Use "YM" for the months after the whole years; avoid "MD".

What DATEDIF is used for

Ages from dates of birth, years of service for HR reports and anniversaries, contract and subscription lengths in months, and how many days a ticket or invoice has been open.

Arguments

ArgumentRequiredWhat it is
start_dateYesThe earlier date, such as a start date or a date of birth.Watch out: If it's later than end_date, the result is #NUM!.
end_dateYesThe later date. Use a fixed "as of" cell for reports, or TODAY() for a live count.
unitYes"Y" complete years, "M" complete months, "D" days, "YM" months left over after whole years, "YD" days left over after whole years, "MD" days left over after whole months (Microsoft advises against "MD").

Common mistakes

  • Putting the later date first: #NUM!.

  • Dividing days by 365: leap years make it drift.

  • Forgetting the quotes around the unit: DATEDIF(C2,H2,Y) is #NAME?; it must be "Y".

  • Using "MD" for leftover days: Microsoft warns it can give a negative number, a zero or an inaccurate result.

In Google Sheets

Google Sheets has DATEDIF with the same three arguments (start_date, end_date, unit) and the same unit letters, so an age or tenure formula works in both apps.

Errors you may see with DATEDIF

  • #NUM!: start_date is later than end_date. Swap them, or wrap the pair in MIN and MAX.
  • #NAME?: The unit is missing its quotes, so the app reads Y as a name.
  • #VALUE!: One of the dates is text the app can't read as a date.

Questions

How do I calculate age from a date of birth?

DATEDIF(birth, TODAY(), "Y") gives the age in completed years. For a report that must not change tomorrow, use a fixed date cell instead of TODAY(). More in the age and date difference guide.

How do I show years and months, like 7 years 2 months?

Combine two units: DATEDIF(C2,$H$2,"Y")&" years "&DATEDIF(C2,$H$2,"YM")&" months". For Amara that's 7 years 2 months: "YM" counts the months left after the whole years.

Is DATEDIF still supported?

Yes. Microsoft documents it and keeps it to support older workbooks from Lotus 1-2-3, but advises against its "MD" unit. Google Sheets has it too, with the same units.

How is DATEDIF different from YEARFRAC?

DATEDIF counts whole units only: 7 years. YEARFRAC returns the years with decimals, like 7.21, which suits pro-rata pay or interest.

Sources

Official documentation the facts on this page were checked against.

Practise DATEDIF on a live sheet

Lesson 27, Years, months and tenure (Unit 7, Dates and time maths), has 5 graded exercises, checked instantly, with steps and hints when you're stuck. Pro