Jump to content

Calculating pace with php (time and pace)


davidcriniti

Recommended Posts

I have a table where I'm storing my marathon and other race results. One column ( race_time_total - TIME format) and another column ( race_distance_numeric - decimal(65,3) format) are being used here.

 

 

Assuming the race_distance_numeric is the distance of the race in either km or miles (Eg: marathon being 42.195km), how to I calculate the pace?

 

I've used:

$pace_per_k = $row_content['race_time_total'] / $row_content['race_distance_numeric']  

.... but am not getting expected results when I echo $pace_per_k

 

Any tips?

 

Link to comment
https://forums.phpfreaks.com/topic/293536-calculating-pace-with-php-time-and-pace/
Share on other sites

You might want to use the TIME_TO_SEC(race_time_total) function in your query so that it converts hours/minutes/seconds into just seconds, and then divide. Then format your result back into H:M:S to display. That can actually all be done within the query without needing PHP.

Speed is measured in meters per second; you will have to convert otherwise.  You will also have to reverse your formula.

speed = distance (meters) / time (seconds)

CroNix is correct.  This can all be calculated within the query, but you cannot subtract time without using the built-in MySQL functions for doing so.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

 

In your case, i would go with cronix' idea of using TIME_TO_SEC()

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.