Date Arithmetic and INTERVAL
Add and subtract dates with INTERVAL, compute durations, and build relative date filters like 'last 7 days'.
Date and Time Types Recap
Four core temporal types in PostgreSQL:
DATE— calendar day, no timeTIME— time of dayTIMESTAMP— date + time, no zoneTIMESTAMPTZ— date + time + zone (recommended for events)
INTERVAL: A Span of Time
INTERVAL is a duration. You add or subtract it from a date/timestamp:
SELECT NOW() + INTERVAL '1 day';
SELECT NOW() - INTERVAL '30 days';
SELECT NOW() + INTERVAL '3 months 2 weeks';
SELECT INTERVAL '1 hour' + INTERVAL '15 minutes';All lessons in this course
- Date Arithmetic and INTERVAL
- EXTRACT, DATE_TRUNC, AGE
- Time Zones: TIMESTAMP vs TIMESTAMPTZ
- Common Date Reports (MTD, WoW, YoY)