-2

what I want to do is calculate the latein these time:

  1. Time-in = 22:00 (10:00 PM)
  2. Time-out = 1:30 (1:30 AM)

The output should be 3:30 i want to get this output

How can I calculate the difference and what built-in function in php should be used to achieved this? Can someone give me a clue?

hihihihi
  • 68
  • 1
  • 5
  • 29

1 Answers1

2

Assuming your times are strings in the form HH:mm, this will work:

$in = new DateTime('22:00');
$out = new DateTime('01:30');
// if in is > out, assume out is on the next day
if ($in > $out) $out->add(new DateInterval('P1D'));
$diff = $out->diff($in);
echo $diff->format('%H:%i');
Nick
  • 138,499
  • 22
  • 57
  • 95