Add or subtract a time interval from a date or timestamp value. Syntax varies more than almost any other operation across SQL engines.
Adds or subtracts an interval from a date or timestamp, the standard way to shift dates forward or backward. DATEDIFF in SQL Server returns the day count between dates; date functions vary significantly across databases.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | all | DATE_ADD(date, INTERVAL n unit) and DATE_SUB(date, INTERVAL n unit). Also supports + INTERVAL shorthand. Units: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, and compound types (SECOND_MICROSECOND, etc.). |
| PostgreSQL | ✓ Supported | all | Uses + / - operators with INTERVAL literals. Interval syntax is flexible: '7 days', '1 month 2 days', '2 hours 30 minutes'. AGE(ts1, ts2) returns a human-readable interval between two timestamps. INTERVAL arithmetic is the most expressive of any engine. |
| SQL Server | ✓ Supported | all | DATEADD(unit, n, date) is the only method — no INTERVAL type or + operator for dates. Units spelled out: year, quarter, month, week, day, hour, minute, second, millisecond, microsecond, nanosecond. |
| Oracle | ✓ Supported | all | DATE + n adds n days (integer arithmetic). For months/years use ADD_MONTHS(date, n). INTERVAL types exist for precise interval arithmetic. No DATEADD function. |
| SQLite | ✓ Supported | all | datetime() and date() functions accept a modifier string. Modifiers: '+N days', '+N months', '+N years', 'start of month', 'weekday N', etc. No INTERVAL type or DATEADD function. |
Date arithmetic is one of the least portable areas of SQL. SQL Server requires DATEADD() — no operator shorthand. Oracle's DATE + n adds days only; months require ADD_MONTHS(). PostgreSQL's INTERVAL arithmetic is the most expressive. SQLite's modifier string approach ('now', '+7 days') is unique and surprisingly capable.
DATE_ADD(date, INTERVAL n unit) and DATE_SUB(date, INTERVAL n unit). Also supports + INTERVAL shorthand. Units: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, and compound types (SECOND_MICROSECOND, etc.).
Uses + / - operators with INTERVAL literals. Interval syntax is flexible: '7 days', '1 month 2 days', '2 hours 30 minutes'. AGE(ts1, ts2) returns a human-readable interval between two timestamps. INTERVAL arithmetic is the most expressive of any engine.
DATEADD(unit, n, date) is the only method — no INTERVAL type or + operator for dates. Units spelled out: year, quarter, month, week, day, hour, minute, second, millisecond, microsecond, nanosecond.
DATE + n adds n days (integer arithmetic). For months/years use ADD_MONTHS(date, n). INTERVAL types exist for precise interval arithmetic. No DATEADD function.
datetime() and date() functions accept a modifier string. Modifiers: '+N days', '+N months', '+N years', 'start of month', 'weekday N', etc. No INTERVAL type or DATEADD function.