PsychoX PsychoX - 1 month ago 10
PHP Question

Subtract time in PHP

I'm looking for an answer for few hours now, but I can't find one.

I'm writing simple script. User set work start time, and end time. So for example somebody is working from 8:00 to 16:00.
How Can I subtract this time to see how long person has been working?

I was experimenting with strtotime(); but without success...

fab fab
Answer

A bit nicer is the following:


$a = new DateTime('08:00');
$b = new DateTime('16:00');
$interval = $a->diff($b);

echo $interval->format("%H");

That will give you the difference in hours.