Skip to content

AGE

Return the difference between two timestamps or the difference between the current timestamp and a future timestamp.

AGE(timestamp [, timestamp])

To specify timestamp literals with this function, use the TIMESTAMP keyword.

For example, calculate your age by comparing the current date with your birthdate. For example:

premdb=# SELECT AGE(TIMESTAMP '2016-05-23', TIMESTAMP '1990-09-04');
          age           
-------------------------
 25 years 8 mons 19 days
(1 row)

You can also run this query by using the CURRENT_DATE or CURRENT_TIMESTAMP function as the first argument.

Find out how long ago a specific match was played:

premdb=# SELECT matchday, AGE(matchday) 
FROM match WHERE seasonid=2 AND htid=2 AND atid=52;
     matchday       |           age           
---------------------+-------------------------
 1993-11-06 00:00:00 | 22 years 6 mons 21 days
(1 row)

Parent topic:Datetime Functions