The function calculates the time difference between two datetime values and returns the difference in seconds.
SECONDS_DIFF(<end_datetime>, <start_datetime>)
| Parameter | Description |
|---|---|
<end_datetime> | Required. The ending datetime value. Supports the DATETIME and DATE type. |
<start_datetime> | Required. The starting datetime value. Supports the DATETIME and DATE type. |
<end_datetime> is later than <start_datetime>, returns a positive value.<end_datetime> is earlier than <start_datetime>, returns a negative value.<end_datetime> and <start_datetime> are equal, returns 0.SELECT SECONDS_DIFF('2025-01-23 12:35:56', '2025-01-23 12:34:56');
+----------------------------------------------------------------------------------------------------------+ | seconds_diff(cast('2025-01-23 12:35:56' as DATETIMEV2(0)), cast('2025-01-23 12:34:56' as DATETIMEV2(0))) | +----------------------------------------------------------------------------------------------------------+ | 60 | +----------------------------------------------------------------------------------------------------------+