Time difference in units

Asked

Viewed 106 times

0

Right now I have the time difference working but as I have it makes the difference in hours, that is, from 11:00 to 12:30 the difference is 1:30 and I enter 1.30, but I wanted him to enter 1.50.

I want the time difference in units, not hours.

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

$intervalo = $inicio->diff($fim);
$dhora = $intervalo->format('%H.%i');
  • Want to 'round up' the difference? what is the criterio?

  • I just want the time difference in units.

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

  • Why 1.50 if the correct is 1.30, do you want to add another 20 minutes? If you want the difference in minutes, just convert the hours into minutes and add up to the 30 minutes. If you want the difference in hours, take the minutes and divide by 60 and add to the hours.

1 answer

0


There is no parameter to format in this form. Take the minute 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);
  • Thank you very much, I’ve been trying and we missed the list part and the explosion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.