本文介绍了添加1小时到datetime数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我有一个数据库中有一个datetime类型的字段,其中我添加用户访问一个页面的时间。当用户再次来时,我想检查他的第一次访问和当前的间隔。如果小于或等于1小时,那么我想向他显示一些信息。我这样存储时间
2011-03-04 00:25:01
我想问的问题是如何检查PHP中的间隔
解决方案
如果您有PHP> = 5.3,您可以使用对象和功能:
$ 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数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!