MYSQL Round the datetime to 15 minute

前端 未结 5 900
囚心锁ツ
囚心锁ツ 2021-01-17 12:58

I want to update the datetime round to 15 minutes in a MYSQL database table.

For Example:

If the dateTime is 2013-10-08 10:36:00, I want to conv

5条回答
  •  迷失自我
    2021-01-17 13:28

    Use the same method as in the question you linked, but use UNIX_TIMESTAMP functions instead. This will round either down or up to the nearest 15 minutes, remove the + 450 part if you want to round only down.

    mysql> select FROM_UNIXTIME(((UNIX_TIMESTAMP('2013-08-07 12:05') + 450) DIV 900) * 900) AS roundtime;
    +---------------------+
    | roundtime           |
    +---------------------+
    | 2013-08-07 12:00:00 |
    +---------------------+
    

提交回复
热议问题