0Pricing
SQL Academy · Lesson

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 time
  • TIME — time of day
  • TIMESTAMP — date + time, no zone
  • TIMESTAMPTZ — 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

  1. Date Arithmetic and INTERVAL
  2. EXTRACT, DATE_TRUNC, AGE
  3. Time Zones: TIMESTAMP vs TIMESTAMPTZ
  4. Common Date Reports (MTD, WoW, YoY)
← Back to SQL Academy