Skip to main content
Scalar function
Aliases: timestamp_diff NULL unit or temporal arguments yield NULL; unknown unit raises an error. Unrepresentable temporal values or overflowing microsecond differences yield NULL.

Syntax

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

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

Alias calling form: TIMESTAMPDIFF

  • The function name is double-quoted to select its ordinary function-call spelling.

Reverse the start and end times

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