I have two variables, $from
and $to
.
$from
is 08:00:00 and $to
is 10:00:00. How can I get the difference between them in hours?
For example in the above case, I want to get only 2
.
Thanks.
I have two variables, $from
and $to
.
$from
is 08:00:00 and $to
is 10:00:00. How can I get the difference between them in hours?
For example in the above case, I want to get only 2
.
Thanks.
$from = "08:00:0";
$to = "10:00:00";
$start_datetime = new DateTime(date('Y-m-d').' '.$from);
$end_datetime = new DateTime(date('Y-m-d').' '.$to);
$timeDiff=$start_datetime->diff($end_datetime);
echo $hour = $timeDiff->format('%h hours');
echo $min = $timeDiff->format('%i min');
echo $sec = $timeDiff->format('%s sec');
Actually I was doing it right, I had some other code issues.. If someone needs it though:
$hour = (strtotime($to) - strtotime($from)) / 3600;