
Averaging Time  Sorry, crosspost
Hi all,<BR><BR>Sorry this is a crosspost from the standard asp q&a forum but this question seems too advanced for the normal forum.<BR><BR>I'm trying to find the average time of this value: 00:06:43:974<BR>which is the elapsed time of a race. The number of laps that have occured is 6, but simply dividing this by 6 won't work.<BR>Also, using the cdate function like this:<BR>dtmAverage = cDate(dtmElapsed/6) <BR>returns a value like this: 1/8/1900 3:30:00 PM<BR><BR>Any thoughts?<BR>

Non standard representation..
00:06:43:974 isn't a standard time representation in any system I know of. Hmmm...maybe UK? But anyway, it's obviously not recognized by CDate. Is that supposed to be 6 hours 43 minutes 974 seconds??? Or, more likely, 6 minutes 43.974 seconds?<BR><BR>Anyway, VBScript won't help you here, because it only deals with Date/Time values that are accurate to the nearest second.<BR><BR>So you'll have to do the math yourself. <BR><BR>I will assume that you really *do* have the form shown above (3 colons, instead of 2 colons and a period):<BR><BR><%<BR>strElapsed = "00:06:43:974"<BR>temp = Split( strElapsed, ":" )<BR>' get number of milliseconds in that elapsed time<BR>millisecs = 1000 * ( temp(0) * 3600 + temp(1) * 60 + temp(2) ) + temp(3)<BR>' number of milliseconds per lap<BR>lapmillis = millisecs / numberOfLaps<BR>' now convert that back to human readable time:<BR>' first, just the milliseconds<BR>millis = Int( lapmillis MOD 1000 ) ' ensure no fraction of a millisecond<BR>' then toss away milliseconds...<BR>lapsecs = lapmillis 1000 ' yes, that really is a backwards slash<BR>' and get just seconds...<BR>seconds = lapsecs MOD 60<BR>' and toss away seconds...<BR>lapmins = lapsecs 60<BR>' and get just minutes...<BR>minutes = lapmins MOD 60<BR>' and tossing away minutes should get hours...<BR>hours = lapmins 60<BR>' then make it into a string:<BR>strLaptime = Right( "0" & hours, 2 ) & ":" _<BR> & Right( "0" & minutes, 2 ) & ":" _<BR> & Right( "0" & seconds, 2 ) & ":" _<BR> & Right( "00" & millis, 3 )<BR>%><BR><BR>Give that a shot. If bugs, let me know.<BR><BR>

RE: Non standard representation..
Thanks heaps. <BR><BR>The time format is: hours:minutes:seconds:milliseconds<BR><BR>This might be of interest.<BR>The timing from an endurance ski race with all the live data being stored in database on a ski field, then fed to our webservers a few hundred kms away. The race can last up to 20 hours too.

So did you try it?
I typed it in "blind", so no guarantees it works right off.<BR><BR>

RE: So did you try it?
I've tried it with a few other values and got some wierd results for division by 1.<BR>Here: (elapsedtime  laps)<BR>00:04:00:288  4 = 00:00:40:048 (seems correct)<BR>00:01:03:529  1 = 00:00:10:588 (incorrect)<BR><BR>

DOH  My mistake... wrong lap value plugged in
Sorry, works fine :)<BR><BR>My mistake (I feel like an idiot)

Let me guess...
You had 6 laps hard coded, instead of getting the value dynamically.<BR><BR>00:04:00:288 would not be 40 seconds when divided by 4. But funny how 4 minutes = 240 seconds which is 6 times 40. Heh!<BR><BR>

RE: Let me guess...
Yup, nice guess<BR><BR>All seems to work fine. Thanks for your help. if you are keen to see the final site, email me: raarky@hotmail.com
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

