MYSQL Date Time Round To Nearest Hour

前端 未结 8 528
孤独总比滥情好
孤独总比滥情好 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条回答
  •  情歌与酒
    2020-12-09 15:26

    I think this is the best way, since it also will use the least amount of resources-

    date_add(date(date_completed), interval hour(date_completed) hour) as date_hr
    

提交回复
热议问题