SQL - Scalar functions - YEARS_BETWEEN
The YEARS_BETWEEN function returns the number of full years between the specified arguments.
The schema is SYSIBM.
If there is less than a full year between expression1 and expression2, the result is zero. If expression1 is later than expression2, the result is positive. If expression1 is earlier than expression2, the result is negative. If expression1 or expression2 contains time information, this information is also used to determine the number of full years. If expression1 or expression2 does not contain time information, a time of midnight (00.00.00) is used for the argument that is missing time information.
The result of the function is an INTEGER. If either argument can be null, the result can be null. If either argument is null, the result is the null value.
The YEARS_BETWEEN function is a synonym of the following expression:
YEAR( TIMESTAMP( expression1, 12 ) - TIMESTAMP( expression2, 12 ) )
SET :NUM_YEARS = YEARS_BETWEEN(DATE '2013-02-28', DATE '2012-02-29')
SET :NUM_YEARS = YEARS_BETWEEN(DATE '2013-12-31', DATE '2001-01-01')
SET :NUM_YEARS = YEARS_BETWEEN(TIMESTAMP '2001-01-01-00.00.00', TIMESTAMP '2013-12-31-23.59.59')