I'm trying to calculate my min/km average of my total run.
Currently I have ran ($this->totaltime) 3113 seconds, ($this->distance) 6313.59 and my pace should be 08:13 min/km (yes this was very slow!)
Code I'm using:
// Pace
function getPace() {
$dis_pace = $this->distance / 1000;
$pace = $this->totaltime / $dis_pace / 60;
return $pace;
}
I think I'm missing something here..
[EDIT] The problem is I get 8.21 but need to have the results in time 08:13. [/EDIT]
Anybody?
Try this one :
// Pace
function getPace() {
$dis_pace = $this->distance / 1000;
//getting seconds per km
$pace = $this->totaltime / $dis_pace;
//getting minutes from $pace
$min = floor($pace / 60);
//adding 0 before, if lower than 10
$min = ($min > 10) ? $min : '0'.$min;
//getting remaining seconds
$sec = $pace % 60;
//adding 0 before, if lower than 10
$sec = ($sec > 10) ? $sec : '0'.$sec;
return $min.":".$sec;
}