Category: FUNCTION | Updated: 2026-11-22
How to Use the DATEDIF Function in Google Sheets | Calculate the Duration (Years, Months, Days) Between Two Dates
How to Use the DATEDIF Function
The DATEDIF function calculates the duration between two dates (start_date and end_date) in a specified unit (years, months, or days). It is extremely useful for calculating exact age from a birth date or years and months of service from a hire date.
Syntax
=DATEDIF(start_date, end_date, unit)
- start_date: The start date of the period.
- end_date: The end date of the period (must be on or after
start_date). - unit: The unit for the result, enclosed in double quotation marks:
"Y": Completed years in the period"M": Completed months in the period"D": Total days in the period"YM": Remaining months after subtracting full years (ignoring years)"YD": Remaining days after subtracting full years (ignoring years)"MD": Remaining days after subtracting full years and months (ignoring years and months)
Examples
Here are the results for each unit when start_date is 2020/04/01 and end_date is 2026/11/22.
| A (Start Date) | B (End Date) | C (Formula) | Result | Description |
|---|---|---|---|---|
| 2020/04/01 | 2026/11/22 | =DATEDIF(A2, B2, "Y") |
6 | 6 full years elapsed |
| 2020/04/01 | 2026/11/22 | =DATEDIF(A3, B3, "M") |
79 | 79 full months elapsed in total |
| 2020/04/01 | 2026/11/22 | =DATEDIF(A4, B4, "D") |
2426 | 2,426 days elapsed |
| 2020/04/01 | 2026/11/22 | =DATEDIF(A5, B5, "YM") |
7 | 6 years and 7 months elapsed |
| 2020/04/01 | 2026/11/22 | =DATEDIF(A6, B6, "MD") |
21 | 6 years, 7 months, and 21 days elapsed |
Common Errors and Tips
#NUM!error (start_date>end_date): Ifstart_dateis later thanend_date,DATEDIFreturns#NUM!. If you want to compare against future dates without errors, useIFto check order and swap the dates if needed.- Forgetting quotes around
unit: EnteringYorMwithout double quotation marks causes a#NAME?error. - Dates that include timestamps: If you pass a date-time value (like
NOW()), a later time of day onstart_datethan onend_datecan prevent a full day from being counted. UseTODAY()orINT()when comparing dates only.
Frequently Asked Questions
Q. Does DATEDIF appear in Google Sheets' formula autocomplete?
A. Google Sheets does show DATEDIF in autocomplete, though some environments display only minimal documentation. Typing "=DATEDIF(start_date, end_date, "unit")" works reliably.
Q. How do I include both the start date and end date in the day count?
A. Using "D" in DATEDIF returns the difference (end date minus start date). To make the count inclusive of the start date, add "+1" to the result.