PostgreSQL 18 reference · Date and Time Functions
PostgreSQL AGE() Function
Subtract dates and return a 'symbolic' interval in years, months and days. With one argument it counts from today.
PostgreSQL 18
Syntax
age(timestamp, timestamp) | age(timestamp)
Parameters
| Parameter | Description |
|---|---|
timestamp |
The later and the earlier value. |
Return value
interval.
Examples
SELECT age(DATE '2026-10-22', DATE '2018-03-01') AS tenure;
Output
tenure ------------------------ 8 years 7 mons 21 days (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT name, EXTRACT(year FROM age(DATE '2026-10-22', hire_date)) AS full_years
FROM employees
LIMIT 3;
Output
name | full_years -------------+------------ Sofia Reyes | 8 Omar Haddad | 8 Mei Chen | 7 (3 rows)
Run this on your computer — see “Get Started” for setup.
In other languages
TIMEDIFF()· SQLiteJULIANDAY()· SQLite
Related
EXTRACT()· Get one field from a date, time or interval, such as the year, month, day of week or epoch seconds.NOW()· Return the current date and time with time zone, fixed at the start of the transaction. current_timestamp is the same.- SQL Date Functions · tutorial