Say I have this:
$date1=date_create(date('H:I', strtotime('8:00')));
$date2=date_create(date('H:I', strtotime('18:00')));
$diff1=date_diff($date1,$date2);
echo $diff1->format("%h:%I");
which outputs 10:00 (hours), but now i want to compare this:
$date3=date_create(date('H:I', strtotime('8:30')));
$date4=date_create(date('H:I', strtotime('17:45')));
$diff2=date_diff($date3,$date4);
echo $diff2->format("%h:%I");
which outputs 9:15
. So, how can I have the diff and the sign (if it's negative) between $diff1
and $diff2
? I just want to get that 45 minutes negative (in this case).