YEARS_DIFF

Overview

Returns the number of years between two dates or timestamps. The result equals the first argument minus the second argument.

Syntax

YEARS_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 years_diff('2026-01-01', '2024-01-01'); -- 2 SELECT years_diff('2024-01-01', '2026-01-01'); -- -2 SELECT years_diff('2024-12-31', '2024-01-01'); -- 0 SELECT years_diff(NULL, '2024-01-01'); -- NULL