Try this:
Public Function FormatDateTimeWithMS(ByVal dDate As Date, Optional
strFormat)
Dim lMilliseconds As Long
Dim bSecondRoundedToUpper As Boolean
lMilliseconds = GetMilliseconds(dDate, bSecondRoundedToUpper)
' if the second gets rounded to upper substract one second
If bSecondRoundedToUpper Then
dDate = DateAdd("s", -1, dDate)
End If
' check to see if the strFormat is missing
If Not IsMissing(strFormat) Then
FormatDateTimeWithMS = Format(dDate, strFormat)
Else
FormatDateTimeWithMS = Format(dDate, "yyyymmdd Hh:Nn:Ss") ' You can
add your own format
End If
FormatDateTimeWithMS = FormatDateTimeWithMS & ":" &
Format(lMilliseconds, "000000")
End Function
Public Function GetMilliseconds(dOriginalDate As Date, ByRef
bSecondRoundedToUpper As Boolean) As Long
Dim strDateTime As String
Dim dRoundedDateTime As Date
' get the string (without milliseconds)
strDateTime = CStr(dOriginalDate)
' return it to the datetime (this one doesn't have milliseconds)
dRoundedDateTime = CDate(strDateTime)
' check if we're below zero
If dOriginalDate > 0 Then
' check if the rounded date is later than the original
If dRoundedDateTime > dOriginalDate Then
' substract one second
dRoundedDateTime = DateAdd("s", -1, dRoundedDateTime)
' return the flag set to on
bSecondRoundedToUpper = True
Else
' return the flag set to off
bSecondRoundedToUpper = False
End If
Else
' check if the rounded date is prior to the original
If dRoundedDateTime < dOriginalDate Then
' add one second (by deducting it! - bug in VB?)
dRoundedDateTime = DateAdd("s", -1, dRoundedDateTime)
' return the flag set to on
bSecondRoundedToUpper = True
Else
' return the flag set to off
bSecondRoundedToUpper = False
End If
End If
' ms are the number of ms in one day times the difference of the rounded
and the orignal date
GetMilliseconds = 86400000 * Abs(dOriginalDate - dRoundedDateTime)
End Function
You'll need to call it using a datetime value from SQL Server or the like.
Pete
-----Original Message-----
From: Alstom [mailto:Alstom@v...]
Sent: Tuesday, December 10, 2002 4:02 AM
To: professional vb
Subject: [pro_vb] Milliseconds
Members of The List -
Anyone knows how to return the current time up to millisecond precision?
Brad.
DISCLAIMER : Volkswagen of South Africa (Pty) Ltd
Any views expressed in this message are those of the individual sender.
No liability shall attach whatsoever to VWSA from this communication except
where the sender is acting on specific authority of VWSA, such authority
being public record and acknowledged by VWSA by nature of the employee's
functions. This document may in no way be photocopied, printed, scanned or
electronically duplicated for any purposes other than that for which it was
originally
intended.
If you are not the intended recipient of this communication, please discard
this message and notify VWSA immediately at postmaster@v...