addition of time
Posted by bschultz (bschultz), 27 October 2003Can someone point me in the right direction on how to add time in PHP.
The format would be like this
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?
Posted by admin (Graham Ellis), 27 October 2003Of 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 2003Graham,
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.
(hope you get a good night's sleep!
Posted by admin (Graham Ellis), 28 October 2003Example of formatting a time in seconds into minutes and seconds, as per your format:
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 2003thanks, Graham. Pretty easy to understand now that I see it in front of my face. I appreciate it!
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho