DATEDIF
Returns the difference between two dates in a requested unit.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=DATEDIF(start_date, end_date, unit)
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
start_date | number | Required | — |
end_date | number | Required | — |
unit | any | Required | — |
Remarks
- A date argument may be text holding a date or time (
"10/26/1999","1999-10-26 14:05"), read as its serial; text that is neither a number nor a date returns#VALUE!. - Supported units are
"Y","M","D","MD","YM", and"YD". - Unit matching is case-insensitive.
- Both endpoints are interpreted with the workbook's date system (Excel 1900 or Excel 1904).
Differences from Excel
With "YD", Formualizer's February 29 normalization can give a different day count in leap-day edge cases.
Error cases
- If
start_date > end_date, the function returns#NUM!.
Examples
Count elapsed days across a month boundary.
Formula =DATEDIF(DATE(2024,1,1),DATE(2024,2,15),"d")
Expected result 45
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Count complete months between the same dates.
Formula =DATEDIF(DATE(2024,1,1),DATE(2024,2,15),"m")
Expected result 1
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
The elapsed interval between identical dates is zero.
Formula =DATEDIF(DATE(2024,1,1),DATE(2024,1,1),"d")
Expected result 0
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A start date after the end date falls outside the supported interval.
Formula =DATEDIF(DATE(2024,2,15),DATE(2024,1,1),"d")
Expected result #NUM!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Difference in days
Formula =DATEDIF(44197, 44378, "D")
Expected result 181
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Complete months difference
Formula =DATEDIF(44197, 44378, "M")
Expected result 6
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
How are unit strings interpreted in DATEDIF?
Unit text is case-insensitive, but only Y, M, D, MD, YM, and YD are supported; other units return #NUM!.