Name

ADDTIME( )

Synopsis

ADDTIME(datetime, datetime)

This function returns the date and the time for given string or column, incremented by the time given as the second argument (d hh:mm:ss). If a negative number is given, the time is subtracted, and the function is the equivalent of SUBTIME(). This function is available as of Version 4.1.1 of MySQL.

SELECT NOW( ) AS Now,
       ADDTIME(NOW( ), '1:00:00.00') AS 'Hour Later';
+---------------------+---------------------+
| Now                 | Hour Later          |
+---------------------+---------------------+
| 2005-01-11 23:20:30 | 2005-01-12 00:20:30 |
+---------------------+---------------------+

Notice that the hour was increased by one, and because the time is near midnight, the function causes the date to be altered by one day, as well. To increase the date, add the number of days before the time (separated by a space) like so:

SELECT NOW( ) AS Now,
       ADDTIME(NOW( ), '30 0:0:0') AS 'Thirty Days Later';
+---------------------+---------------------+
| NOW( )               | Thirty Days Later   |
+---------------------+---------------------+
| 2005-01-11 23:20:30 | 2005-02-10 23:20:30 |
+---------------------+---------------------+

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.