DATEDIF Function
Calculates the difference between two dates in days, months, or years. Commonly used for age calculations and duration tracking.
ExcelGoogle Sheets
Syntax
DATEDIF(start_date, end_date, unit)Parameters
| Parameter | Description |
|---|---|
| start_date | The start date (must be earlier than or equal to end_date). |
| end_date | The end date. |
| unit | "Y" = years, "M" = months, "D" = days, "MD" = days ignoring months/years, "YM" = months ignoring years, "YD" = days ignoring years. |
Examples
Calculate age in years
=DATEDIF(A2, TODAY(), "Y")Result: 30 (if born 30 years ago)
Months between two dates
=DATEDIF("2024-01-15", "2024-09-20", "M")Result: 8
Full age display
=DATEDIF(A2,TODAY(),"Y") & " years, " & DATEDIF(A2,TODAY(),"YM") & " months"Result: 30 years, 5 months
Tips & Best Practices
- •DATEDIF is undocumented in Excel (no autocomplete) but fully functional.
- •Start date must be ≤ end date or you'll get a #NUM! error.
- •The "MD" unit can produce incorrect results in some edge cases — test carefully.
- •Google Sheets fully supports and documents DATEDIF.
Related Formulas
Need a different formula?
Describe what you need in plain English and our AI will generate the formula for you.
Try Formula Generator