DATE_DIFF

All functions > DATE AND TIME > DATE_DIFF

Returns the difference between the two given timestamps in the given unit.

Signatures

Returns: The number of units between the two timestamps as BIGINT

DATE_DIFF(timestamp1: TIMESTAMP, timestamp2: TIMESTAMP, unit: VARCHAR) → BIGINT
sql
ParameterTypeRequiredDescription
timestamp1TIMESTAMPYesThe start timestamp
timestamp2TIMESTAMPYesThe end timestamp
unitVARCHARYesThe time unit for the difference (e.g., 'day', 'hour')

Notes

  • Calculates difference between two timestamps
  • Result is timestamp2 - timestamp1 in the specified unit
  • Common units: 'second', 'minute', 'hour', 'day', 'week', 'month', 'year'
  • Positive if timestamp2 is after timestamp1, negative otherwise
  • Useful for calculating durations and time elapsed

Examples

FeatureQL
SELECT
    f1 := DATE_DIFF(TIMESTAMP '2024-03-15 10:00:00', TIMESTAMP '2024-03-22 10:00:00', 'day'),  -- Difference in days
    f2 := DATE_DIFF(TIMESTAMP '2024-03-15 10:00:00', TIMESTAMP '2024-03-15 13:00:00', 'hour')  -- Difference in hours
;
Result
f1 BIGINTf2 BIGINT
73

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19