Search code examples
phptimemampstrtotimemaxlength

Difference between two time stamps in PHP


It seems to me that this should echo 11 hours but it returns 12; what am I missing?

$start_time = "06:00";
$end_time = "17:00";
$LOD = date("H:i", ((strtotime($end_time) - strtotime($start_time))));
echo  "Length of day: " . $LOD . " hours";

Update: running on my MBPro in a MAMP environment; system time set to 24 hr.


Solution

  • Using date that way doesn't make any sense.

    If you want a minimum sense, then you should add strtotime("00:00") as your initial time.

    (end - start) + init