Averaging Time - Sorry, crosspost

# Thread: Averaging Time - Sorry, crosspost

1. Senior Member
Join Date
Dec 1969
Posts
511

## 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&#039;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&#039;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>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Non standard representation..

00:06:43:974 isn&#039;t a standard time representation in any system I know of. Hmmm...maybe UK? But anyway, it&#039;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&#039;t help you here, because it only deals with Date/Time values that are accurate to the nearest second.<BR><BR>So you&#039;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>&#060;%<BR>strElapsed = "00:06:43:974"<BR>temp = Split( strElapsed, ":" )<BR>&#039; get number of milliseconds in that elapsed time<BR>millisecs = 1000 * ( temp(0) * 3600 + temp(1) * 60 + temp(2) ) + temp(3)<BR>&#039; number of milliseconds per lap<BR>lapmillis = millisecs / numberOfLaps<BR>&#039; now convert that back to human readable time:<BR>&#039; first, just the milliseconds<BR>millis = Int( lapmillis MOD 1000 ) &#039; ensure no fraction of a millisecond<BR>&#039; then toss away milliseconds...<BR>lapsecs = lapmillis 1000 &#039; yes, that really is a backwards slash<BR>&#039; and get just seconds...<BR>seconds = lapsecs MOD 60<BR>&#039; and toss away seconds...<BR>lapmins = lapsecs 60<BR>&#039; and get just minutes...<BR>minutes = lapmins MOD 60<BR>&#039; and tossing away minutes should get hours...<BR>hours = lapmins 60<BR>&#039; then make it into a string:<BR>strLaptime = Right( "0" & hours, 2 ) & ":" _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; & Right( "0" & minutes, 2 ) & ":" _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; & Right( "0" & seconds, 2 ) & ":" _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; & Right( "00" & millis, 3 )<BR>%&#062;<BR><BR>Give that a shot. If bugs, let me know.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
511

## 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.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## So did you try it?

I typed it in "blind", so no guarantees it works right off.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
511

## RE: So did you try it?

I&#039;ve tried it with a few other values and got some wierd results for division by 1.<BR>Here: (elapsedtime &#124 laps)<BR>00:04:00:288 &#124 4 = 00:00:40:048 (seems correct)<BR>00:01:03:529 &#124 1 = 00:00:10:588 (incorrect)<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
511

## DOH - My mistake... wrong lap value plugged in

Sorry, works fine :)<BR><BR>My mistake (I feel like an idiot)

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## 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>

8. Senior Member
Join Date
Dec 1969
Posts
511

## 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
•