Scalar function
Aliases: timestampdiff
NULL unit or temporal arguments yield NULL; unknown unit raises an error. Unrepresentable temporal values or overflowing microsecond differences yield NULL.
Syntax
Scalar
Timestampdiff quoted (scalar)
- Quote the function name and pass a STRING unit, for example
"timestampdiff"('hour', start, end). The unquoted TIMESTAMPDIFF keyword form is rejected.
Arguments
Scalar, timestampdiff quoted
Returns
- Type: BIGINT
- NULL behavior: NULL unit or temporal arguments yield NULL; unknown unit raises an error. Unrepresentable temporal values or overflowing microsecond differences yield NULL.
Properties
Units
- Input unit: Temporal values
- Output unit: Specified complete elapsed units
Usage notes
- Arguments are ordered as (unit, start, end).
- Calendar units use complete units; shorter fixed units truncate incomplete elapsed intervals.
Examples
Complete elapsed hours
- The function name is double-quoted to select its ordinary function-call spelling.
Limitations
- Use
"timestampdiff"('hour', start, end) or TIMESTAMP_DIFF('hour', start, end). The unquoted TIMESTAMPDIFF(HOUR, start, end) form is rejected.
Last modified on October 15, 2026