Update only Time in a mysql DateTime field

前端 未结 12 1521
北海茫月
北海茫月 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:03

    This what helped me. I convert time to minutes firstly: 150 for 2:30 am.

    UPDATE lesson SET starts_at = DATE_ADD(Date(starts_at), INTERVAL 150 MINUTE)
    

    Minutes are enough accurate for me, though you can use other units: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add

提交回复
热议问题