Add Time Interval
Add time interval to a date or datetime, return the result of date or datetime type.
Syntax
addYears(exp0, expr1)
addMonths(exp0, expr1)
addDays(exp0, expr1)
addHours(exp0, expr1)
addMinutes(exp0, expr1)
addSeconds(exp0, expr1)
Return Type
Date, Timestamp, depends on the input.
Examples
SELECT to_date(18875), addYears(to_date(18875), 2);
+---------------+-----------------------------+
| to_date(18875) | addYears(to_date(18875), 10) |
+---------------+-----------------------------+
| 2021-09-05 | 2023-09-05 |
+---------------+-----------------------------+
SELECT to_date(18875), addMonths(to_date(18875), 2);
+---------------+-----------------------------+
| to_date(18875) | addMonths(to_date(18875), 2) |
+---------------+-----------------------------+
| 2021-09-05 | 2021-11-05 |
+---------------+-----------------------------+
SELECT to_date(18875), addDays(to_date(18875), 2);
+---------------+---------------------------+
| to_date(18875) | addDays(to_date(18875), 2) |
+---------------+---------------------------+
| 2021-09-05 | 2021-09-07 |
+---------------+---------------------------+
SELECT to_datetime(1630833797), addHours(to_datetime(1630833797), 2);
+------------------------+-------------------------------------+
| to_datetime(1630833797) | addHours(to_datetime(1630833797), 2) |
+------------------------+-------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 11:23:17 |
+------------------------+-------------------------------------+
SELECT to_datetime(1630833797), addMinutes(to_datetime(1630833797), 2);
+------------------------+---------------------------------------+
| to_datetime(1630833797) | addMinutes(to_datetime(1630833797), 2) |
+------------------------+---------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 09:25:17 |
+------------------------+---------------------------------------+
SELECT to_datetime(1630833797), addSeconds(to_datetime(1630833797), 2);
+------------------------+---------------------------------------+
| to_datetime(1630833797) | addSeconds(to_datetime(1630833797), 2) |
+------------------------+---------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 09:23:19 |
+------------------------+---------------------------------------+