Update only Time in a mysql DateTime field

前端 未结 12 1529
北海茫月
北海茫月 2020-12-09 07:44

How can I update only the time in an already existing DateTime field in MySQL? I want the date to stay the same.

12条回答
  •  忘掉有多难
    2020-12-09 08:26

    Asuming you have a DATE field and TIME field and want to inject the time into the date, try this:

    UPDATE mytable
    SET mydatefield = ADDTIME( DATE_FORMAT(mydatefield,'%Y-%m-%d 00:00:00'), mydatefield)
    WHERE myid = ...
    

提交回复
热议问题