PHP add up two time variables

If the answer you expect is 15:50:00 and you want to use strtotime and date functions, you need to subtract the seconds $time1 and $time2 share when you transform them to unix timestamps:

$time1 = '15:20:00';
$time2 = '00:30:00';
$time = strtotime($time1) + strtotime($time2) - strtotime('00:00:00');
$time = date('H:i:s', $time);

Leave a Comment