DAYS_DIFF

Overview

Returns the number of days between two dates or timestamps. Result = first argument - second argument. Equivalent to DATEDIFF(DAY, ...) but with a more concise syntax.

Syntax

DAYS_DIFF(<end>, <start>)

Parameters

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

Returns NULL if either argument is NULL.

Examples

SELECT days_diff('2024-02-01', '2024-01-01'); -- 31 SELECT days_diff('2024-01-01', '2024-02-01'); -- -31 SELECT days_diff('2024-01-01 18:00:00', '2024-01-01 00:00:00'); -- 0 SELECT days_diff(NULL, '2024-01-01'); -- NULL