添加1小时到datetime数据类型 [英] Add 1 hour to datetime datatype
本文介绍了添加1小时到datetime数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样存储时间
2011-03-04 00:25:01
我想问的问题是如何检查PHP中的间隔
解决方案
如果您有PHP> = 5.3,您可以使用 DateTime 对象和功能:
$ visit = DateTime :: createFromFormat('Ymd H:i:s','2011-03-04 00:25:01');
$ now = new DateTime(now);
$ diff = $ now-> diff($ visit);
Hello I have a field in database that has type of datetime in which I add time when user visit a page. When user again comes I want to check the interval between his first visit and current. If it is less or equal to 1 hour then I want to show him some message. I store time like this
2011-03-04 00:25:01
The thing that I want to ask that how to check the interval in PHP
解决方案
If you have PHP >= 5.3 you can use DateTime objects and functions:
$visit = DateTime::createFromFormat('Y-m-d H:i:s', '2011-03-04 00:25:01');
$now = new DateTime("now");
$diff = $now->diff($visit);
这篇关于添加1小时到datetime数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文