Top  | Previous | Next

Date and Time / dateDiff

dateDiff(date, date, field)

Calculates the difference between the two dates, returning the result as a floating point value in the units specified by field, which must be a string matching one of these values:

"ms"
"second"
"sec"
"minute"
"min"
"hour"
"hr"
"day"
"week"
"month"
"year"

 

The return value will be a floating point value, meaning that parts of units are considered. The exception to this rule is for the months and years fields, which will always return an integral difference. If the second date argument is after the first, the return value will be positive, otherwise it will be negative.

 

dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-2-24 8:15:30"), "minute")

...returns 15.5

 

dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-3-12 9:28:00"), "month")

...returns 1.0

 

dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-3-12 9:28:00"), "day")

...returns 17.02