date-time
INTERVAL arithmetic
Adds or subtracts a duration to a date/timestamp. Postgres uses the SQL-standard INTERVAL literal directly; MySQL wraps it in DATE_ADD/DATE_SUB; SQLite uses date modifiers.
timestamp + INTERVAL '1 day' | DATE_ADD(dt, INTERVAL 1 DAY) Parameters / Modifiers
| Parameter | Purpose |
|---|---|
| 'n days' / 'n hours' / 'n months' | Postgres INTERVAL unit strings |
| DATE_ADD / DATE_SUB | MySQL functions that accept INTERVAL n UNIT |
| datetime(dt, '+1 day') | SQLite modifier syntax |
| AGE(a, b) | Postgres companion returning an interval difference |
Examples
SELECT NOW() + INTERVAL '7 days'; Postgres: timestamp one week from now
SELECT DATE_ADD(NOW(), INTERVAL 7 DAY); MySQL: same result
SELECT datetime('now', '+7 days'); SQLite equivalent
SELECT * FROM sessions WHERE created_at > NOW() - INTERVAL '24 hours'; Postgres: rows created in the last day
Dialect notes / Gotcha
Adding 'INTERVAL 1 month' to Jan 31 lands on Feb 28/29, not Mar 3 — engines clamp to the last day of month. MySQL will not accept the Postgres-style 'INTERVAL '1 day'' literal outside DATE_ADD.
Related functions
NOW / CURRENT_TIMESTAMP
Returns the current transaction (or statement) timestamp. Both spellings work in Postgres and MySQL; SQLite prefers CURRENT_TIMESTAMP or datetime('now').
DATE_TRUNC
Rounds a timestamp down to the beginning of the specified unit (year, month, week, day, hour, etc.). Native to Postgres; MySQL uses DATE_FORMAT or manual arithmetic.
EXTRACT / DATE_PART
Pulls a numeric component (year, month, day, hour, minute, dow, epoch) out of a date or timestamp. EXTRACT is SQL-standard and works in Postgres and MySQL; DATE_PART is a Postgres synonym.
← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet