DSQL, PSQL
Changed in
2.5
Syntax
Result type
BIGINT
Description
Returns the number of years, months, weeks, days, hours, minutes, seconds or milliseconds elapsed between two date/time values. (The unit is new in 2.5.)
DATE
andTIMESTAMP
arguments can be combined. No other mixes are allowed.With
TIMESTAMP
andDATE
arguments, all units can be used. (Prior to Firebird 2.5, units smaller thanDAY
were disallowed forDATE
s.)With
TIME
arguments, onlyHOUR
,MINUTE
, andMILLISECOND
can be used.
It does, however, look at all the bigger units. So:
A negative result value indicates that moment2 lies before moment1.
Examples
datediff (hour from current_timestamp to timestamp '12-Jun-2059 06:00')
datediff (minute from time '0:00' to current_time)
datediff (day from current_date to cast(? as date))
See also