MONTHS_DIFF

Overview

Returns the number of months between two dates or timestamps. Result = first argument - second argument.

Syntax

MONTHS_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 months_diff('2025-03-01', '2024-01-01'); -- 14 SELECT months_diff('2024-01-01', '2025-03-01'); -- -14 SELECT months_diff('2024-02-01', '2024-01-01'); -- 1 SELECT months_diff(NULL, '2024-01-01'); -- NULL