| |||||||||||
| |||||||||||
addition of time Posted by bschultz (bschultz), 27 October 2003 Can someone point me in the right direction on how to add time in PHP.For example: The format would be like this Code:
I need to add that to get 2:08.0 (2 minutes, 8 seconds) Then, I'll need to divide that number by the number of races run for the average time per race (which in this case would be (1:04.0) Is this possible in PHP? Thanks. Brian Posted by admin (Graham Ellis), 27 October 2003 Of course - anything's possible in PHP ![]() [Sorry - been a long day's drive and it has warped my sense of humour] The best way to deal with time arithemetic (in any language) is to convert to seconds, do the sums, and convert back again. I would suggest a regular expression match to extract the minutes and seconds, multipy the minutes by 60 and add the seconds, do the maths, and use the / and % operators to convert back, followed by sprintf. Would you like me to code an example? Too tired to do so tonight (It's 11 pm in Dublin where I am) but I could do so tomorrow evening .... Posted by bschultz (bschultz), 28 October 2003 Graham,I can strip it down to seconds...but would need some help getting it back into a time format. Any help would be greatly appreciated. Brian (hope you get a good night's sleep! ![]() Posted by admin (Graham Ellis), 28 October 2003 Example of formatting a time in seconds into minutes and seconds, as per your format:Code:
Available for test at http://www.wellho.net/demo/secdo.php4 Got a good night's sleep, yes, thanks ... much recovered now (24 hours later). Posted by bschultz (bschultz), 29 October 2003 thanks, Graham. Pretty easy to understand now that I see it in front of my face. I appreciate it!This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |