i want to calculate different between two datetime in seconds and check if the result > 300sec
$d1 = new DateTime("2016-03-25 19:29:21");
$d2 = new DateTime(date('Y-m-d H:i:s'));
please check following code:
$datetime1 = new DateTime();
$datetime2 = new DateTime('2016-03-25 19:29:21');
$interval = $datetime1->diff($datetime2);
$elapsed = $interval->format('%y years %m months %a days %h hours %i minutes %S seconds');
echo $elapsed;
check this
if($d2->format('U')-$d1->format('U')>300){
// greater than 300
}else{
// less than 300
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With