Full Version: Convert UNIX Time to MS Access
UtterAccess Forums > Microsoft® Access > Access Date + Time
Hello everyone
’m trying to find a way to convert a UNIX timestamp to the standers universal timestamp. At this point I can’t even make sense of the UNIX time stamping system.
I would like to be able to use Microsoft access to do the conversion.
Does anyone one a why to convert the UNIX timestamp into a MMDDYY formatted time. Any help would be greatly appreciated
R. Hicks
This should help you ...
[color="green"]' Convert Unix Epoch time (Time in seconds since Jan 1, 1970)
' UTS_Offset is the hours offset from GMT where you are locate
' Eastern Time (US) = -5
' Central Time (US) = -6
' Mountain Time (US) = -7
' Pacific Time (US) = -8
Public Function fConvertEpoch(varEpochVal As Variant, UTC_OffSet As Integer) As Variant
Dim tmpDate As Date
Dim StartDaylight As Date
Dim EndDaylight As Date

If IsNull(varEpochVal) Then Exit Function

tmpDate = DateAdd("s", varEpochVal, #1/1/1970#)
tmpDate = DateAdd("h", UTC_OffSet, tmpDate)

[color="green"]' Get the last day of March by subtracting one day from 4/1[/color]
StartDaylight = DateAdd("d", -1, DateSerial(Year(tmpDate), 4, 1))

[color="green"]' Now skip to the next Sunday[/color]
StartDaylight = DateAdd("d", 5 - WeekDay(StartDaylight), StartDaylight)
StartDaylight = DateAdd("h", 2, StartDaylight)
EndDaylight = DateSerial(Year(tmpDate), 11, 1)

[color="green"]' Back up to the previous Sunday[/color]
EndDaylight = DateAdd("d", -5 + WeekDay(EndDaylight), EndDaylight)
EndDaylight = DateAdd("h", 1, EndDaylight)

If (tmpDate >= StartDaylight And tmpDate < EndDaylight) Then
  tmpDate = DateAdd("h", 1, tmpDate)
End If

fConvertEpoch = tmpDate

End Function

Thanks Ricky
R. Hicks
No problem .. wink.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.