如何检测php中指定的日期过去3小时? 我有我最近的剧本,我不知道我的剧本在哪里出错了。
$currentdate = "2012-05-29 21:00:01";
$dateassigned = "2012-05-29 18:00:00";
$startTime = mktime() - 3*3600;
$getdate = strtotime($date);
if($getdate >= $startTime) {
//if get date already past with 3 hour this will show yes
echo "yes";
} else {
echo "no";
}
对此问题有任何帮助吗? 谢谢。
答案 0 :(得分:0)
不确定您是否想要比较第二个
date("now -3 hours");
应该返回时间
星期二,2012年5月29日14:48:01 +000001
您可以使用strtotime()
进行比较,或使用date_diff()进行php> = 5.3
答案 1 :(得分:0)
如果我理解你的意思,这应该有效:
$now = date('Y-m-j H:i:s');
$last3Hour = strtotime ( '-3 hour' , strtotime ( $now ) ) ;
$specificDate = "2012-05-29 18:00:00";
if(strtotime($specificDate) >= $last3Hour) {
echo "yes";
} else {
echo "no";
}