How to add and subtract fom time in MySQL
Luckily for us there is an ADDTIME function we can use to add and remove from times… The syntax is as follows: ADDTIME(datetime,time_to_change) example
SELECT `emp_id` , `clock_time` , ADDTIME( '-01:00:00', `clock_time` ) AS new_time FROM `timeclock`
Will return
emp_id | clock_time | new_time |
10059 | 08:30:55 | 07:30:55 |
10059 | 08:31:06 | 07:31:06 |
10059 | 08:31:28 | 07:31:28 |
10046 | 08:33:44 | 07:33:44 |
An Update example
UPDATE `timeclock` SET `clock_time` = ADDTIME( '-01:00:00', `clock_time` ) WHERE `id` BETWEEN 40967 AND 41022
Recent Comments