Function · Date and time
Excel DATEDIF function
The Excel DATEDIF function returns complete years, months, or days between two dates. From January 15, 2024 to July 4, 2026 is 2 years, 29 months, and 901 days. Excel leaves it out of the function list.
Syntax =DATEDIF(start_date, end_date, unit)
=DATEDIF(DATE(2024,1,15),DATE(2026,7,4),"Y")Arguments
| Name | Required | What to pass |
|---|---|---|
| start_date | Required | The earlier date. |
| end_date | Required | The later date. If it is earlier than the start, the result is #NUM!. |
| unit | Required | "Y" complete years, "M" complete months, "D" days, "YM" months after stripping whole years, "YD" days after stripping whole years, "MD" days after stripping whole months. |
Examples
Complete years from January 15, 2024 to July 4, 2026
=DATEDIF(DATE(2024,1,15),DATE(2026,7,4),"Y")Result 2
| A | B | |
|---|---|---|
| 1 | Start | 1/15/2024 |
| 2 | End | 7/4/2026 |
| 3 | Whole years | 2 |
DATEDIF measures a completed interval. From January 15, 2024 to July 4, 2026 the completed years are 2, because July 4 has not yet reached January 15 of a third year. The completed months are 29. Strip the 2 years off and 5 months remain, which is the YM unit. The day count, D, is 901, the same difference DAYS would return.
Excel still calculates DATEDIF and still hides it in the Insert Function dialog, so a misspelled unit looks like a broken name. The MD unit, days ignoring months, is the one to avoid. It has known wrong results when the dates sit near the ends of months of different lengths. Y, M, D, and YM are the units that match this example. If the end date is earlier than the start, the result is #NUM!, not a negative.