Calculate the Age in Years in PostgreSQL

Postgres has the age() function that returns the age in years, months, and days based on two dates.

This works fine unless you only want to return the age in years.

For example, you simply want to return a person’s age based on their birthday. You want something like 32 instead of 32 years 4 mons 67 days, which is what age() is likely to return.

Fortunately there’s an easy way to do this in PostgreSQL.

Continue reading