Ad Code

Question for PHP Time Calculator Based on Distance

 As pointed out, the problem is that you are not working the minutes out as minutes.

To reduce the main calculation to 1 step, you can add the stops into the time taken by the speed and distance, dividing the total time for the stops (stops * 5) by 60 (to make it into a decimal representing parts of an hour). Then split this into the hours and minutes without need for any further adjustments.

$time = $distance / $speed + ($stops * 5) / 60;
$hours = intval($time);
$minutes = ($time - $hours) * 60;
which with your values, will give
Based on the information given your trip will take 1 hours and 25 minutes.  

 

Post a Comment

0 Comments