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
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
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.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Name | Dept | Started | Born | Salary | Level | Years here | As of |
| 2 | Amara Osei | Sales | 15 Apr 2019 | 2 Aug 1990 | $58,000 | 2 | 7 | 30 Jun 2026 |
| 3 | Ben Fischer | Support | 9 Jan 2023 | 21 Nov 1996 | $41,000 | 1 | 3 | |
| 4 | Lina Chen | Engineering | 1 Sep 2016 | 14 Mar 1987 | $88,000 | 4 | 9 | |
| 5 | Diego Alvarez | Sales | 28 Jun 2021 | 30 Jun 1993 | $52,000 | 2 | 5 | |
| 6 | Eva Novak | Finance | 12 Feb 2018 | 5 Dec 1985 | $74,000 | 3 | 8 | |
| 7 | Farid Haddad | Engineering | 4 Mar 2024 | 19 Jan 1998 | $68,000 | 2 | 2 | |
| 8 | Grace Kim | Support | 19 Oct 2020 | 27 Sep 1991 | $45,000 | 2 | 5 | |
| 9 | Hugo Martin | Finance | 11 May 2015 | 8 Apr 1979 | $88,000 | 4 | 11 | |
| 10 | Ines Varga | Engineering | 14 Nov 2022 | 28 Feb 1995 | $79,000 | 3 | 3 | |
| 11 | Kenji Mori | Sales | 25 Aug 2025 | 16 Jul 2000 | $39,000 | 1 | 0 |
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. DATEDIF: Counts the whole years between
C2and$H$2.start=`C2`: the earlier dateend=`$H$2`: the later dateunit=`"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
| Argument | Required | What it is |
|---|---|---|
| start_date | Yes | The 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_date | Yes | The later date. Use a fixed "as of" cell for reports, or TODAY() for a live count. |
| unit | Yes | "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
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.