📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

TIMESTAMP_DIFF



Calculates the difference between two timestamps and returns the result as an INTERVAL.

Syntax

TIMESTAMP_DIFF(<timestamp1>, <timestamp2>)

Return Type

INTERVAL (formatted as hours:minutes:seconds).

Examples

This example shows that the time difference between February 1, 2025, and January 1, 2025, is 744 hours, corresponding to 31 days:

SELECT TIMESTAMP_DIFF('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP); ┌──────────────────────────────────────────────────────────────────┐ │ timestamp_diff('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP) │ ├──────────────────────────────────────────────────────────────────┤ │ 744:00:00 │ └──────────────────────────────────────────────────────────────────┘

Was this page helpful?