0

I have two hours format value

1) [start_time] => 07:30
2) [end_time] => 13:50

I want difference in hours between this two time.

For this case 07:30 to 13:50 it's difference of 6.00 hours.

so i need ans 6.00

Uttam Panara
  • 541
  • 2
  • 10
  • 28
  • what you have tried so far? please add code – Jalpesh Patel Sep 19 '17 at 08:00
  • Possible duplicate of [Date and Time 24 hour format Get Difference in PhP](https://stackoverflow.com/questions/19899519/date-and-time-24-hour-format-get-difference-in-php) – Edwin Sep 19 '17 at 08:01
  • Possible duplicate of [How to calculate the difference between two dates using PHP?](https://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – Vineet Jain Sep 19 '17 at 08:03

1 Answers1

1

You can use DateTime classes, and use the diff() method. Create two DateTime objects with the different times, and apply diff() on one of them, with the other as the argument. Then you just print the format() which is applicable, which in your example is %H:%I.

$first = new DateTime("7:30");
$second = new DateTime("13:30");

$diff = $second->diff($first);
echo $diff->format("%H:%I"); // 06:00
Qirel
  • 25,449
  • 7
  • 45
  • 62