How to Calculate Date Differences in PostgreSQL
Last updated July 25, 2026 · By the SaturnSQL team
Subtracting two dates gives an integer number of days; subtracting timestamps gives an interval. Use age() for a calendar-aware breakdown and extract(epoch from ...) to convert an interval to seconds.
SELECT
current_date - '2026-01-01'::date AS days_elapsed,
now() - created_at AS raw_interval,
age(now(), created_at) AS calendar_diff,
extract(epoch FROM now() - created_at) / 3600 AS hours_elapsed
FROM orders
LIMIT 5;Filter by age
SELECT id, created_at
FROM orders
WHERE created_at < now() - interval '30 days';Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free