Function dateAdd()
returns a new time shifted from the original time.
Arguments:
- Original time <datetime | timestamp | string>
- Offset <number>
- Offset unit <string>, valid options: year, month, day, hour, minute, second
Returns:
- New time <datetime | timestamp>
Common Usage
Example: Direct calculate
uncollect ["2023-04-30 22:00:00", "2023-01-15 22:00:00"] as a
uncollect [2, -30] as b
uncollect ["day", "minute"] as c
return table(a, b, c, dateAdd(a, b, c))
| a | b | c | dateAdd(a, b, c) |
|---------------------|-----|--------|---------------------|
| 2023-04-30 22:00:00 | 2 | day | 2023-05-02 22:00:00 |
| 2023-01-15 22:00:00 | -30 | minute | 2023-01-15 21:30:00 |
Example: Multiply and calculate
uncollect ["2023-04-30 22:00:00", "2023-01-15 22:00:00"] as a
uncollect [2, -30] as b
uncollect ["day", "minute"] as c
with dateAdd(a, b, c) as d
return table(a, b, c, d)
| a | b | c | d |
|---------------------|-----|--------|---------------------|
| 2023-04-30 22:00:00 | 2 | day | 2023-05-02 22:00:00 |
| 2023-04-30 22:00:00 | 2 | minute | 2023-04-30 22:02:00 |
| 2023-04-30 22:00:00 | -30 | day | 2023-03-31 22:00:00 |
| 2023-04-30 22:00:00 | -30 | minute | 2023-04-30 21:30:00 |
| 2023-01-15 22:00:00 | 2 | day | 2023-01-17 22:00:00 |
| 2023-01-15 22:00:00 | 2 | minute | 2023-01-15 22:02:00 |
| 2023-01-15 22:00:00 | -30 | day | 2022-12-16 22:00:00 |
| 2023-01-15 22:00:00 | -30 | minute | 2023-01-15 21:30:00 |