I trying calculate the difference of days but I need the return of this function in hours.
Well, in my tests follow the code:
<?php
$date1 = new DateTime('2014-05-15 11:00:00');
$date2 = new DateTime('2014-05-14 08:00:00');
$date3 = new DateTime('2014-05-16 10:00:00');
if($date1 != $date2){
$diff = $date3->diff($date2);
if($diff->format('%r%h') > 3){
echo 'error';
echo '<br />';
echo $diff->format('%r%h');
}else{
echo 'ok';
echo '<br />';
echo $diff->format('%r%h');
}
}else{
echo 'OK';
}
?>
When I call "echo" with the formated value in this case the value is ever "0". The PHP only calculate the difference in hours. If I need the real return in hour I need calculate the value manual? like:
$days = ($diff->format('%d') * 24 * 60);
Not have the better method to solve this case?