INTERVAL (time span)
Last updated: 2026-11-04
INTERVAL (time span)
INTERVAL represents a span of time, stored internally as separate month, day and time components. That split lets it express calendar amounts whose length varies, such as "1 year 2 months", alongside exact durations such as "36 hours". Since PostgreSQL 14 the default output uses ISO 8601 style. Adding one to a TIMESTAMP yields a new timestamp, which makes it the most useful type for time arithmetic.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
INTERVAL —— time span, stored separately as months / days / time-of-day
INTERVAL '1 day 2 hours' —— literal form
INTERVAL '1-2' —— ISO 8601 year-month form: 1 year 2 months
Returns:Stores a time span. Adding one to a TIMESTAMP or a DATE advances it by calendar rules (one month lands on the end of a shorter month), while adding one to a TIME affects only the time-of-day part.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | span | longer | normalized | col_type
----+----------------+----------------+----------------+----------
1 | 1 day 02:00:00 | 1 day 02:30:00 | 1 day 02:00:00 | interval
2 | 01:30:00 | 02:00:00 | 01:30:00 | interval
📌 Key Points
- INTERVAL '90 minutes' renders as 01:30:00, and justify_hours() folds every full 24 hours into days, turning 30 hours into 1 day 06:00:00.
- One month is not a fixed 30 days: 2024-01-31 plus 1 month gives 2024-02-29, while 2023-01-31 gives 2023-02-28, because months advance by calendar length.
- Trade-off: use INTERVAL for calendar amounts such as billing periods and subscriptions; for exact durations such as latency, BIGINT milliseconds or numeric is simpler.