DATE_ADD()
All functions > DATE AND TIME > DATE_ADD()
Returns the date/timestamp after adding a given number of a given units to the given date or timestamp.
Signatures
Returns: A new timestamp with the interval added
DATE_ADD(timestamp: DATE | TIMESTAMP, unit: VARCHAR, value: BIGINT) → TIMESTAMP sql
| Parameter | Type | Required | Description |
|---|---|---|---|
timestamp | `DATE | TIMESTAMP` | Yes |
unit | VARCHAR | Yes | The time unit to add (e.g., 'day', 'hour', 'month') |
value | BIGINT | Yes | The number of units to add |
Notes
- Adds a specified interval to a date or timestamp
- Common units: 'second', 'minute', 'hour', 'day', 'week', 'month', 'year'
- Value can be positive (future) or negative (past)
- DATE inputs are promoted to midnight TIMESTAMP before the addition
- Useful for date arithmetic and scheduling
- Handles month/year boundaries correctly
Examples
Date inputs
FeatureQL
SELECT
f1 := DATE_ADD(DATE '2024-03-15', 'day', 7), -- Add 7 days to a date
f2 := DATE_ADD(DATE '2024-03-15', 'month', 2) -- Add 2 months to a date
;Result
| f1 TIMESTAMP | f2 TIMESTAMP |
|---|---|
| 2024-03-22T00:00:00 | 2024-05-15T00:00:00 |
Timestamp inputs
FeatureQL
SELECT
f1 := DATE_ADD(TIMESTAMP '2024-03-15 10:00:00', 'day', 7), -- Add 7 days
f2 := DATE_ADD(TIMESTAMP '2024-03-15 10:00:00', 'hour', 3), -- Add 3 hours
f3 := DATE_ADD(TIMESTAMP '2024-03-15 10:00:00', 'month', -1) -- Subtract 1 month
;Result
| f1 TIMESTAMP | f2 TIMESTAMP | f3 TIMESTAMP |
|---|---|---|
| 2024-03-22T10:00:00 | 2024-03-15T13:00:00 | 2024-02-15T10:00:00 |
On this page