ADDTIME
Adds the specified time to a time or datetime value.
MySQL 8.1
ADDTIME(datetime, time)Parameters
- datetimeDATETIME
- Time or datetime
- timeTIME
- Time to add, can be negative and include days: «1 02:00:00»
Return value
A datetime if datetime contains a date, otherwise a time (TIME) not beyond 838:59:59; NULL if an argument is NULL
Examples
An hour added to a datetime
MySQL 8.1
SELECT ADDTIME('2022-06-16 23:30:00', '01:00:00') AS shifted;Negative time and days
MySQL 8.1
SELECT ADDTIME('10:00:00', '-02:30:00') AS earlier,
ADDTIME('10:00:00', '1 02:00:00') AS plus_day;Class start with a delay
MySQL 8.1
SELECT id,
start_pair,
ADDTIME(start_pair, '00:10:00') AS start_with_delay
FROM Timepair;Details
The first argument must contain a time. A date without a time is read as a time, and the result makes no sense: ADDTIME('2022-06-16', '01:00:00') returns 01:20:22. For dates, use DATE_ADD or + INTERVAL.
The paired function SUBTIME subtracts time. PostgreSQL has no such functions; time is added with an operator: value + INTERVAL '1 hour'.