Jump to content

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()

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.