Calculate Age with PostgreSQL | SQL Bits | Kovolff
Channel: prelearn
Date: 02/11/2020

To calculate ages in PostgreSQL is very simple, as this database engine has the age() function just for this purpose.

General form of age
age(end_date, start_date)

If your end_date is the current date, then the age() function simplifies to:
age(start_date)
i.e. age(CAST(“birthdate” AS DATE))

This produces a duration in years, months and days.

To just get the years, use the extract() function
i.e. 
EXTRACT(YEAR FROM age(CAST(“birthdate” AS DATE)))

#sql #age #postgresql #calculate #databases