I'm attaching to a database that contains timestamp data in the
traditional UNIX format, i.e. a long integer containing the number of
elapsed seconds since 1/1/70. I'd like to find an algorithm for
converting this to the Date format for reporting purposes (CDate isn't
it - I know there is a C function to convert and save the time as a
struct but I'd rather do everything in VB for simplicity).
Any ideas?
TIA,
Kevin
> I'm attaching to a database that contains timestamp data in the
> traditional UNIX format, i.e. a long integer containing the number of
> elapsed seconds since 1/1/70. I'd like to find an algorithm for
> converting this to the Date format for reporting purposes (CDate isn't
> it - I know there is a C function to convert and save the time as a
> struct but I'd rather do everything in VB for simplicity).
Try DateAdd("s", lUNIXTimeStamp, "1/1/1970").
--
Peter F. Dubuque - dub...@tiac.net - Enemy of Reason(TM) O-
The easiest way to do this is:
Function UnixToPCDate(Seconds As Long, Optional TimeZone As Integer)
Const Epoch = "1/1/70"
Const SecondsInHour = 3600
If IsMissing(TimeZone) Then
UnixToPCDate = DateAdd("s", Seconds, Epoch)
Else
UnixToPCDate = DateAdd("s", Seconds + (TimeZone * SecondsInHour),
Epoch)
End If
End Function
This allows you to pass in the TimeZone as an optional argument. You could
also choose to read this value from the Windows registry.
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DayLightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Declare Function GetTimeZoneInformation Lib "kernel32"
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Function TimeZone() As String
Dim lngRet As Long
Dim intX As Integer
Dim strRet As String
Dim TZI As TIME_ZONE_INFORMATION
lngRet = GetTimeZoneInformation(TZI)
For intX = 0 To 31
If TZI.StandardName(intX) = 0& Then Exit For
strRet = strRet & Chr(TZI.StandardName(intX))
Next
TimeZone = strRet
End Function