How can I work with time in thousandth of seconds

  • Thread starter Thread starter =?ISO-8859-1?Q?Zden=EBk_Hrdina?=
  • Start date Start date
?

=?ISO-8859-1?Q?Zden=EBk_Hrdina?=

I have a database and in some colsumsn i need to work with thousandths
of seconds. But in Time format I can´t adjust time in this format,
minimal are only seconds. Can somebody help me how to do it?
 
You really can't with the built-in Date data type: due to how it stores
date/time values, it's only accurate to about 3 milliseconds.

My recommendation would be to either store your times as number of
milliseconds, and write your own functions to handle the formatting, or else
use a structure that stores the time as the individual components (i.e.:
hours, minutes, seconds, etc), and write your own functions to handle the
arithmetic.
 
I have a database and in some colsumsn i need to work with thousandths
of seconds. But in Time format I can´t adjust time in this format,
minimal are only seconds. Can somebody help me how to do it?

The easiest way is to store your time value as a Long integer representing the
total time as thousandths of a second and then use 2 functions to convert the
value from thousandths to formatted time and formatted time back to thousandths.

The following functions (air code) work for values < 1hour, if your times exceed
1 hour you will need to add another level to the functions. If your times are
less than 1 minute you will need to remove the top level of the functions.

From the debug window -
?fGetThousandths("15:35:985")
935985

?fGetFormatted(935985)
15:35:985

Hide your bound control containing the time value and use an unbound textbox to
manipulate the data.

Use the OnCurrent event to set the unbound textbox -
Me.MyUnboundControl = fGetFormatted(Me.MyDataControl)

Use the AfterUpdate event of the unbound control to update the hidden control -
Me.MyDataControl = fGetThousandths(Me.MyUnboundControl)


'==============================================
Function fGetThousandths(strTime As String) As Variant
Dim lngMinutes As Long
Dim lngSeconds As Long
Dim intThousandths As Integer

lngMinutes = Left(strTime, (InStr(1, strTime, ":") - 1))
strTime = Mid(strTime, InStr(1, strTime, ":") + 1, 99)
lngSeconds = Left(strTime, (InStr(1, strTime, ":") - 1))
strTime = Mid(strTime, InStr(1, strTime, ":") + 1, 99)
intThousandths = strTime

fGetThousandths = (lngMinutes * 60000) + (lngSeconds * 1000) + intThousandths

End Function
'==============================================
Function fGetFormatted(lngThousandths As Long) As String
Dim lngMinutes As Long
Dim lngSeconds As Long
Dim intThousandths As Integer

lngMinutes = lngThousandths \ 60000
lngThousandths = lngThousandths - (lngMinutes * 60000)
lngSeconds = lngThousandths \ 1000
intThousandths = lngThousandths - (lngSeconds * 1000)
intThousandths = intThousandths

fGetFormatted = lngMinutes & ":" & Format(lngSeconds, "00") & ":" &
Format(intThousandths, "000")

End Function
'==============================================

Wayne Gillespie
Gosford NSW Australia
 
You really can't with the built-in Date data type: due to how

Yes,
and write your own functions to handle the formatting, or else
Yes,

date/time values, it's only accurate to about 3 milliseconds.

No, it's a floating point number: it's accurate to
4.94065645841247E-324 (which is much smaller than 3E-006),
but the decimal point 'floats' - you can get 3 milliseconds
if you also are storing a date in the same number.....


SQL Server uses the same number of bytes as VB/Jet, but
organised as two longs -- which is why SQL Server can't
handle very small time intervals in a date/time value,
and more importantly, won't handle out-of-range dates....

(david)
 
Back
Top