Calculate running pace from distance and time in PHP

2.4k Views Asked by At

I'm not a programator, I'm not a student. I just play with HTML, CSS and PHP for my own pleasure. For now, I try to make a webpage for my running. I would like to calculate my PACE (mm:ss/KM) from my DISTANCE (KM) and running time (mm:ss) or better (hh:mm:ss).

Can anyone help to PHP begginer? I have no idea how to code it.

<?php
$distance="6.03";
$hours="00";
$minutes="34";
$seconds="13";

$time=($hours*3600)+($minutes*60)+$seconds;
$speed=($time/$distance)/60;
$speed1=date('i:s', $speed);
?>

$distance is 6.03 km
$time gives me rum time in seconds (2053 seconds)
$speed gives mi number 5.67440574903
$speed1 gives me 00:05

1

There are 1 best solutions below

0
Martin On BEST ANSWER

SOLVED! Many thanks to BizziBob

This is correct working code:

<?php 
$distance="6.03";
$hours="00";
$minutes="34";
$seconds="13";

$time=($hours*3600)+($minutes*60)+$seconds;
$speed=$time/$distance;
$formated=date('i:s', $speed);

echo $formated;
?>