Date Difference
Last updated
Was this helpful?
Last updated
Was this helpful?
NB. Most tools use different conventions for referring to date parts. For a full comparison of the different options, go to .
=~DATEDIF!~(‹start_date›, ‹end_date›, "‹date_part›")
NB.:
DATEDIF
reminder syntax is not listed in the usual prompt that appears when you start typing an Excel function.
The ‹date_part› must be wrapped in double quotes or the formula will not calculate.
Supported date parts are as follows (all fractions are rounded down):
Date Part
Equates to
Min : Max Values
"D"
Days
-∞ : ∞
"M"
Months
-∞ : ∞
"Y"
Years
-∞ : ∞
"MD"
Days (irrespective of month & year of the two dates)
0 : 30
"YD"
Days (irrespective of the year of the two dates)
0 : 364
"YM"
Months (irrespective of the year of the two dates)
0 : 11
Excel does not support differences in hours/minutes/seconds when using DATEDIF
.
If you want to find a difference in time, you can use ~TEXT!~(‹end_time›, ‹start_time›, ‹format›) where ‹format› is one of 'h', 'h:mm', or 'h:mm:ss'.
~DATEDIFF!~('‹datepart›', ‹start_date›, ‹end_date›«, start_of_week»)
NB. Supported date parts are as follows (all fractions are rounded up):
Date Part
Equates to
'year'
Years
'quarter'
Quarters
'month'
Months
'week'
Weeks
'day'
Days
'hour'
Hours
'minute'
Minutes
'second'
Seconds
~DATETIMEDIFF!~(‹start_date›, ‹end_date›, '‹date_part›')
NB. Supported date parts are as follows (all fractions are rounded down):
Date Part
Equates to
'year' / 'years'
Years
'month' / 'months'
Months
'day' / 'days'
Days
'hour' / 'hours'
Hours
'minute' / 'minutes'
Minutes
'second' / 'seconds'
Seconds
‹end_date›.~diff!~(‹start_date›«, date_part»)
NB. Supported date parts are as follows (fractions are not rounded):
Date Part
Equates to
'y'
Years
'q'
Quarters
'm'
Months
'w'
Weeks
'd'
Days
~DATEDIFF!~(‹date_part›, ‹start_date›, ‹end_date›)
NB. Supported date parts are as follows (fractions are not rounded):
Date Part
Equates to
year
Years
quarter
Quarters
month
Months
day
Days
week
Weeks
hour
Hours
minute
Minutes
second
Seconds
microsecond
Mircroseconds
nanosecond
Nanoseconds
~datetime.date!~(‹end_date›) - ~datetime.date.!~(‹start_date›)
This returns a date object. To unpack it as a number of days, wrap the difference expression in ()
and append .days
:
NB.:
This requires the datetime
library to be imported.
This returns the difference in days which can be divided/multiplied to give other units.
When manually creating a date, days and months must be entered as a single digit when < 9 (with no padding '0'), e.g. date(2016,9,20)
.
The above examples assume variables have been declared for finishDate
and transferDate
. For more information, go to the chapter .