How to round a DateTime in MySQL?

前端 未结 6 1250
孤城傲影
孤城傲影 2020-12-21 17:48

I want to discretize the DateTime with the resolution of 5 minutes. I did it in C#, but how to convert the following code to MySQL?

DateTime Floor(DateTime d         


        
6条回答
  •  庸人自扰
    2020-12-21 18:21

    from_unixtime(floor(unix_timestamp('2006-10-10 14:26:01')/(60*5))*(60*5))
    +---------------------------------------------------------------------------+
    | from_unixtime(floor(unix_timestamp('2006-10-10 14:26:01')/(60*5))*(60*5)) |
    +---------------------------------------------------------------------------+
    | 2006-10-10 14:25:00                                                       |
    +---------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    you can replace the two 5s with other values

提交回复
热议问题