I am using this code to calculate the time period. In fact, I want the period between two HH:MM:SS moment and have a result in HH:MM:SS format.
$time1 = strtotime('00:00:00');
$time2 = strtotime('00:00:07');
$diff = $time2 - $time1;
$diff = date('H:i:s', $diff);
Please stop using
date functions. Use the
And if you would have searched better, finding difference for two dates has already been all over SO. For instance, my answer here. Slightly changed it would look like:
$create_time = "00:00:00"; $current_time="00:00:07"; $dtCurrent = DateTime::createFromFormat('H:i:s', $current_time); $dtCreate = DateTime::createFromFormat('H:i:s', $create_time); $diff = $dtCurrent->diff($dtCreate); echo $diff->format("%H:%I:%S"); // to get HH:MM:SS format
DateInterval::format for more formatting details.