Scalar function
Aliases: datediff
Returns NULL if a temporal argument or unit is NULL, or a timestamp cannot be represented by the temporal conversion. An unknown non-NULL unit raises an error.
Syntax
Days (scalar)
Units (scalar)
Arguments
Days
Units
Returns
- Type: BIGINT
- NULL behavior: Returns NULL if a temporal argument or unit is NULL, or a timestamp cannot be represented by the temporal conversion. An unknown non-NULL unit raises an error.
Properties
Units
- Input unit: Calendar dates or timestamps
- Output unit: Days for the two-argument form; specified complete units for the three-argument form
Usage notes
- Two-argument order is (end,start); three-argument order is (unit,start,end).
- Two arguments compare local calendar dates and discard time-of-day; three arguments count complete elapsed units.
- Calendar year/quarter/month results use complete calendar units, not a fixed number of seconds. Negative differences are possible.
Examples
Cross a date boundary
Complete elapsed hours
Last modified on October 15, 2026