date - PHP date_diff with if statement doesn't work properly
one text
I'm trying to calculate the difference between two different hours. Everything work fine! I create a function that return me the H:i:s
function dateDifference($date_1 , $date_2 , $differenceFormat = '%r%a' ) {
$datetime1 = date_create($date_1);
$datetime2 = date_create($date_2);
$interval = date_diff($datetime1, $datetime2);
$interval->format('%r%a');
return $interval->format('%r%H:%i:%s');;
}
print dateDifference(date('H:i:s'), $orariof); ///$orariof is any time
This is the result: https://i.postimg.cc/0565G9c3/Immagine-2022-10-31-165134.png
But if I try to add the following if statement, the condition becomes true for the right options, except for one. If anyone could help me understand why the condition become true for the exception, I really appreciate it!
The function:
if(dateDifference(date('H:i:s'), $orariof)>date('H:i:s', strtotime('00:30:00'))){
print dateDifference(date('H:i:s'), $orariof);
}
And the result: https://i.postimg.cc/y830wq1r/Immagine-2022-10-31-165104.png
The if statement print a time difference which shouldn't be printed because the difference is only 9 minutes
Source