Skip to main content

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​

ParameterDescription
unitTime unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
intervalThe time interval to add, typically an integer, which can be positive or negative to add or subtract the time length
datetime_exprA 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 |
+----------------------------------------------+