MYSQL Date Time Round To Nearest Hour

前端 未结 8 537
孤独总比滥情好
孤独总比滥情好 2020-12-09 14:52

I have a date time field in a MySQL database and wish to output the result to the nearest hour.

e.g. 2012-04-01 00:00:01 should read 2012-04-01 00

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 15:23

    If you need to round just time to next hour you may use this:

    SELECT TIME_FORMAT(
      ADDTIME(
        TIMEDIFF('16:15', '10:00'), '00:59:00'
      ),
      '%H:00:00'
    )
    

提交回复
热议问题