Round datetime到最后一小时 [英] Round datetime to last hour

查看:120
本文介绍了Round datetime到最后一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在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));

CodePad演示


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));

CodePad Demo.

这篇关于Round datetime到最后一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆