How to detect past 3 hours from the date assigned in php? I have my recent script i don't know if where did I go wrong in my script.
$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";
}
Any help for this problem? Thank you.
not sure if you want comparison up to the second but
date("now -3 hours");
should return the time
Tue, 29 May 2012 14:48:01 +000001
You can use strtotime()
to do comparison or date_diff() for php >= 5.3
If I understand your mean this should work:
$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";
}