ADDTIME( )

Similar to ADDDATE(), but specifically and supposedly for adding time to a value. However, both MySQL functions allow the addition of date and time to a value.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

ADDTIME(datetime, datetime)

Explanation

This function returns the date and time for a given string or column (in time or datetime format), incremented by the time given as the second argument. If a negative number is given, the time is subtracted. In this case, the function is the equivalent of SUBTIME( ). This function is available as of version 4.1.1 of MySQL.

Examples

SELECT NOW( ) AS Now,
ADDTIME(NOW( ), '1:00:00.00') AS 'Hour Later';

+---------------------+---------------------+
| Now                 | Hour Later          |
+---------------------+---------------------+
| 2007-01-11 23:20:30 | 2007-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   |
+---------------------+---------------------+
| 2007-01-11 23:20:30 | 2007-02-10 23:20:30 |
+---------------------+---------------------+