在我的表中,有一个创建的日期时间字段,其中插入类似于2016-05-25 11:50:35的数据。
假设插入时间为11:50,当前时间为12:10,则差异为20分钟。现在,我需要检查的是在一个变量中获得这个差异,并检查如果差异> 30,则编辑链接将不可见,否则可见。
下面是我的代码。
我从数据库中从创建的datetime字段中提取mins。
$var1 = $post['ShipperRating']['created'];
$time1 = date('i', strtotime($var1));
$finaltime = $time1;
echo $finaltime;发布于 2016-05-25 06:44:16
$createdDateTime = new DateTime($post['ShipperRating']['created']);
$createdDateTime->modify('+30 minutes');
if ($createdDateTime >= new DateTime()) {
echo '<a href="/url">Edit</a>';
}发布于 2016-05-25 06:48:07
使用strtotime (http://php.net/manual/en/function.strtotime.php)将工作..。
$var1 = $post['ShipperRating']['created'];
$time1 = strtotime($var1);
$finaltime = strtotime('+ 30 minutes',$time1);
echo date('Y-m-d H:i:s',$finaltime);发布于 2016-05-25 07:02:28
如果您想通过PHP来完成这个任务,那么您必须在30分钟后刷新页面,并计算从服务器到服务器的时间,这已经显示在其他答案中了。您可以使用头函数来设置刷新页面的时间。
header("Refresh: 300;url='http://example.com/example'");https://stackoverflow.com/questions/37429567
复制相似问题