Round datetime到最后一小时 [英] Round datetime to last hour
问题描述
我在MySQL数据库中有datetime值,必须是
示例,所有这些值:
2013-04-20 07:14:42
2013-04-20 07:19:51
2013-04-20 07:37:26
2013-04-20 07:46:28
2013-04-20 07:59:44
应该向下舍入:
2013-04-20 07:00:00
和
2013-04-20 16:25:34
应该是:
2013- 04-20 16:00:00等...
获取日期值的PHP代码:
$ d = strtotime($ row [date]);
那么,如何舍去datetime值呢?
尝试这个,
$ date =2013-04-20 16:25:34;
echo date(Y-m-d H:00:00,strtotime($ date));
I tried to look for this but I could not find good example of this what im trying to do.
I got datetime values in MySQL database that has to be rounded down when that value is on use.
Example, all these values:
2013-04-20 07:14:42
2013-04-20 07:19:51
2013-04-20 07:37:26
2013-04-20 07:46:28
2013-04-20 07:59:44
Should be rounded down to:
2013-04-20 07:00:00
And
2013-04-20 16:25:34
should be:
2013-04-20 16:00:00 etc...
PHP code that gets date value:
$d = strtotime($row["date"]);
So, how its possible to round down datetime value?
Try this,
$date = "2013-04-20 16:25:34";
echo date("Y-m-d H:00:00",strtotime($date));
这篇关于Round datetime到最后一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!