How to round up age with PostgreSQL?

2

I used the age() function, below, to calculate the age, from a date stored in a table:

select pessoa.*, age(data_nascimento) from pessoa;

Returned the range: 27 years 9 months 9 days

Is it possible to round this range to only 27 years or 27 years ?

The DBMS used: PostgreSQL.

    
asked by anonymous 17.06.2015 / 03:07

2 answers

2

I like to use to_char , it brings many possibilities, it follows example of several functions:

select *,
   date_part('year', age(data_nascimento))||' Anos' AS idade,
   date_trunc('year', age(data_nascimento)) AS idade2,
   extract(year from age(data_nascimento))||' Anos' AS idade3,
   to_char(age(data_nascimento),'yy Anos') as idade4
from pessoa

More information about to_char link

    
29.10.2015 / 02:42
1

You can use the date_part function link

    
17.06.2015 / 09:13