YEARS_BETWEEN

Purpose

This function returns the number of years between two date values.

Syntax

years_between::=

Usage Notes

  • If a timestamp is entered, only the date contained therein is applied for the computation.
  • If the months and days are identical, the result is an integer.
  • If the first date value is earlier than the second date value, the result is negative.
  • For data type TIMESTAMP WITH LOCAL TIME ZONE this function is calculated within the session time zone.

Example

SELECT YEARS_BETWEEN(DATE '2001-01-01', DATE '2000-06-15') YB1,
       YEARS_BETWEEN(TIMESTAMP '2001-01-01 12:00:00',
                     TIMESTAMP '2000-01-01 00:00:00') YB2;