TIMESTAMP_DIFF (Lakehouse v1)
Calculates the difference between two timestamps and returns the result as an INTERVAL.
Analyze Syntax
Section titled “Analyze Syntax”func.timestamp_diff(<timestamp1>, <timestamp2>)Analyze Examples
Section titled “Analyze Examples”func.timestamp_diff(func.to_timestamp('2025-02-01'), func.to_timestamp('2025-01-01'))┌────────────────────────────────────────────────────────────────────────────────────────┐│ func.timestamp_diff(func.to_timestamp('2025-02-01'), func.to_timestamp('2025-01-01')) │├────────────────────────────────────────────────────────────────────────────────────────┤│ 744:00:00 │└────────────────────────────────────────────────────────────────────────────────────────┘SQL Syntax
Section titled “SQL Syntax”TIMESTAMP_DIFF(<timestamp1>, <timestamp2>)Return Type
Section titled “Return Type”INTERVAL (formatted as hours:minutes:seconds).
SQL Examples
Section titled “SQL 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 │└──────────────────────────────────────────────────────────────────┘