SECONDS_DIFF

Overview

Returns the number of seconds between two timestamps. The result equals the first argument minus the second argument.

Syntax

SECONDS_DIFF(<end>, <start>)

Parameters

  • <end>: DATE or TIMESTAMP type, used as the minuend.
  • <start>: DATE or TIMESTAMP type, used as the subtrahend.

Returns NULL if either argument is NULL.

Examples

SELECT seconds_diff('2024-01-01 00:01:00', '2024-01-01 00:00:00'); -- 60 SELECT seconds_diff('2024-01-01 00:00:00', '2024-01-01 00:01:00'); -- -60 SELECT seconds_diff('2024-01-02', '2024-01-01'); -- 86400 SELECT seconds_diff(NULL, '2024-01-01'); -- NULL