AGE_IN_YEARS

Returns the difference in years between two dates, expressed as an integer.

Behavior Type

Syntax

AGE_IN_YEARS( [ date1,] date2 )

Parameters

date1
date2

Specify the boundaries of the period to measure. If you supply only one argument, Vertica sets date1 to CURRENT_DATE. Both parameters must evaluate to one of the following data types:

  • DATE
  • TIMESTAMP
  • TIMESTAMPTZ

If date1 < date2, AGES_IN_YEARS returns a negative value.

Examples

Get the age of someone born March 2 1972, as of June 21 1990:

=> SELECT AGE_IN_YEARS('1990-06-21'::TIMESTAMP, '1972-03-02'::TIMESTAMP);
 AGE_IN_YEARS
--------------
           18
(1 row)

Get the age of someone who was born November 21 1939, as of today:

=> SELECT AGE_IN_YEARS('1939-11-21'::DATE);
 AGE_IN_YEARS
--------------
           77
(1 row)