Full Version: Time.. Hours.. Minutes.. Seconds.. Milliseconds?
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
Coldbrain
Is there a way to format a time with milliseconds? I am working on a project for a friend with racing and he wants his lap times with milliseconds because many of the times are very close.. Seems silly but I can't seem to find it.. perhaps I am just supposed to construct it and decontruct if I want to perform any math on them?

CB
datAdrenaline
To get down to the milliseconds, I use an API call ...

CODE
Public Declare Function GetTickCount Lib "kernel32" () As Long


When called in code, the fuction will return the number of Milleseconds the computer has been ON as a LONG INTEGER.

So to get an elapsed time ... you would need the TickCount from when the race began and the TickCount of when the competitor finished. Note that in SOME circumstances you may need "Rollover" protection.
KingMartin
In addition to what Brent said, if you're speaking about a cell format, try custom format

hh:mm:ss,000

Martin
r_cubed
Try the following code , which like Brent uses an API call, but also has subroutines for 'StartINg' and 'Stopping' with the 'STOP calculating the elapsed time in millisecs.


CODE
Public Declare Function adh_apiGetTime Lib "winmm.dll" _
            Alias "timeGetTime" () As Long

Global lngStartTime As Long
'

'
'
Sub adhStartTimer()
    ' Start the timer, storing the value in
    ' the module global, lngStartTime.
    
    lngStartTime = adh_apiGetTime()
End Sub
'
'


Function adhEndTimer() as Long
    ' End timing, and return the difference between the
    ' current time and lngStartTime
        
    adhEndTimer = adh_apiGetTime() - lngStartTime
    
End Function
Coldbrain
Sorry, wasn't referring to timing with my computer. I pull the data from the racetrack they provide us with actual times I just put them into excel.. I'm really just referring to the formatting.

Thanks everyone,

CB
KingMartin
CB, Does the format I posted above work for you then?
StuKiel
Hi CB,

Remember Martin uses European Regional settings, so you may need to change the format to

hh:mm:ss.000

(sorry to jump in Martin)

Stu.
KingMartin
Hey, didn't I make a statement on how I like the variety of the WRS recently? link

Thanks Stu sad.gif

Martin
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.