Difference of hours in units

0

At this moment I have the difference of hours to work but as I have the difference in hours, that is, from 11:00 a.m. to 12:30 p.m., the difference is 1:30 p.m. and I enter 1.30, but I wanted it to enter 1.50 .

I want the difference of hours in units, not hours.

$inicio = new DateTime($horai);
$fim = new DateTime($horaf);

$intervalo = $inicio->diff($fim);
$dhora = $intervalo->format('%H.%i');
    
asked by anonymous 22.07.2015 / 15:14

1 answer

0

There is no parameter to format in this form. Take the time difference and divide by 60. Then add the time difference

<?php

$inicio = new DateTime("10:00");
$fim = new DateTime("11:30");

$intervalo = $inicio->diff($fim);
$dhora = $intervalo->format('%h.%i');
list($h, $hm) = explode(".", $dhora);

echo $h + ($hm/60);
    
22.07.2015 / 15:35