addYEARS/MONTHS/DAYS/HOURS/MINUTES/SECONDS
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​
Date16, Date32 or DateTime32, depends on the input.
Examples​
mysql> select toDate(18875), addYears(toDate(18875), 2);
+---------------+-----------------------------+
| toDate(18875) | addYears(toDate(18875), 10) |
+---------------+-----------------------------+
| 2021-09-05 | 2023-09-05 |
+---------------+-----------------------------+
mysql> select toDate(18875), addMonths(toDate(18875), 2);
+---------------+-----------------------------+
| toDate(18875) | addMonths(toDate(18875), 2) |
+---------------+-----------------------------+
| 2021-09-05 | 2021-11-05 |
+---------------+-----------------------------+
mysql> select toDate(18875), addDays(toDate(18875), 2);
+---------------+---------------------------+
| toDate(18875) | addDays(toDate(18875), 2) |
+---------------+---------------------------+
| 2021-09-05 | 2021-09-07 |
+---------------+---------------------------+
mysql> select toDateTime(1630833797), addHours(toDateTime(1630833797), 2);
+------------------------+-------------------------------------+
| toDateTime(1630833797) | addHours(toDateTime(1630833797), 2) |
+------------------------+-------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 11:23:17 |
+------------------------+-------------------------------------+
mysql> select toDateTime(1630833797), addMinutes(toDateTime(1630833797), 2);
+------------------------+---------------------------------------+
| toDateTime(1630833797) | addMinutes(toDateTime(1630833797), 2) |
+------------------------+---------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 09:25:17 |
+------------------------+---------------------------------------+
mysql> select toDateTime(1630833797), addSeconds(toDateTime(1630833797), 2);
+------------------------+---------------------------------------+
| toDateTime(1630833797) | addSeconds(toDateTime(1630833797), 2) |
+------------------------+---------------------------------------+
| 2021-09-05 09:23:17 | 2021-09-05 09:23:19 |
+------------------------+---------------------------------------+