I need to add 12 hours to a MySQL TIME
field (not DATETIME
) and I\'m having trouble.
UPDATE `events`
SET start_time = DATE_ADD(sta
set start_time = ADDTIME(start_time,'12:00:00')
DATE_ADD works fine with timestamp etc, but not with TIME
if the developer does not want to update data and wants to add hours or minutes to time. It can be done following way:
The developer can use an AddTime() function to add hours to time column in MySQL. It can be used like below way:
AddTime(COLUMN,’01:00:00′) to add an hour in MySQL time column
AddTime(COLUMN,’00:01:00′) to add a minute in MySQL time column
sql query example:
select id,name,AddTime(login_time,'01:00:00') as login_time FROM `table`
Try using ADDTIME instead of DATE_ADD. You could do SET start_time = ADDTIME(start_time, '12:00:00')
UPDATE `events`
SET start_time = start_time + INTERVAL 12 HOUR
WHERE `start_time` < '11:00:00'
The MySQL functions that accept INTERVAL
arguments are mostly unnecessary; you can just add and subtract intervals with +
and -
.
update my_table SET modified_date = ADDTIME(scheduled_date, '03:15:00')
This will add 3 hours , 15 minutes in modified_date