Retrieve Milliseconds

The following snippet of code shows how you can use Visual Basic to retrieve milliseconds within timestamps.

Public Function Time_To_String_With_Milliseconds(TheTime As Double) As String
Dim Temp As String
Dim TimeFraction As Double
Dim Msc As Long
Dim TempTime As Date

On Error GoTo errc

If TheTime = 0 Then
Time_To_String_With_Milliseconds = ""
Exit Function
End If

TimeFraction = TheTime * 86400#
TimeFraction = TimeFraction - Fix(TimeFraction)

Msc = CLng(TimeFraction * 1000)

TempTime = TheTime - (TimeFraction / 86400#)
If Msc = 1000 Then
Msc = 0
TempTime = DateAdd("s", 1, TempTime)
End If

Time_To_String_With_Milliseconds = LCase(Format$(TempTime, "dd-mmm-yyyy hh:nn:ss") + "." + Format$(Msc, "000"))

errc:

End Function