TIMESTAMPADD
Descriptionβ
The timestampadd
function is used to add a specified time unit (such as year, month, day, hour, minute, second, etc.) to a timestamp or date. This function is commonly used for date and time calculations.
Syntaxβ
TIMESTAMPADD(<unit>, <interval>, <datetime_expr>)
Parametersβ
Parameter | Description |
---|---|
unit | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR |
interval | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length |
datetime_expr | A valid target timestamp or date |
Return Valueβ
The return value is the new date and time, representing the result of adding or subtracting the specified time interval to the given timestamp.
Examplesβ
SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02');
+------------------------------------------------+
| timestampadd(MINUTE, 1, '2019-01-02 00:00:00') |
+------------------------------------------------+
| 2019-01-02 00:01:00 |
+------------------------------------------------+
SELECT TIMESTAMPADD(WEEK,1,'2019-01-02');
+----------------------------------------------+
| timestampadd(WEEK, 1, '2019-01-02 00:00:00') |
+----------------------------------------------+
| 2019-01-09 00:00:00 |
+----------------------------------------------+