In this PostgreSQL post explains how to use the PostgreSQL age function with syntax and examples.
The PostgreSQL age function returns the number of years, months, and days between two dates.
The syntax for the age function in PostgreSQL is:
The two dates to calculate the difference between.
The age function performs two different calculations depending on what parameters are provided.
If date1 is provided, the age function performs the following calculation:
If date1 is NOT provided, the age function performs the following calculation:
The age function will return the result as one of the following formats:
The age function can be used in the following versions of PostgreSQL:
Let's look at some PostgreSQL age function examples and explore how to use the age function in PostgreSQL.
For example: