MySQL add 12 hours to a time field

后端 未结 5 1139
渐次进展
渐次进展 2020-12-03 21:18

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         


        
相关标签:
5条回答
  • 2020-12-03 21:34
    set start_time = ADDTIME(start_time,'12:00:00')
    

    DATE_ADD works fine with timestamp etc, but not with TIME

    0 讨论(0)
  • 2020-12-03 21:41

    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`
    
    0 讨论(0)
  • 2020-12-03 21:47

    Try using ADDTIME instead of DATE_ADD. You could do SET start_time = ADDTIME(start_time, '12:00:00')

    0 讨论(0)
  • 2020-12-03 21:49
    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 -.

    0 讨论(0)
  • 2020-12-03 21:53
    update my_table SET modified_date = ADDTIME(scheduled_date, '03:15:00') 
    

    This will add 3 hours , 15 minutes in modified_date

    0 讨论(0)
提交回复
热议问题