May 2005
Intermediate to advanced
352 pages
14h 39m
English
ADDTIME( )
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 |
+---------------------+---------------------+Read now
Unlock full access