Hello everyone. I am trying to convert a UNIX date/time stamp into normal mm/dd/yyyy hh:nn:ss format in my query. How do I do this taking into account Daylight Savings Time?
Hello everyone. I am trying to convert a UNIX date/time stamp into normal mm/dd/yyyy hh:nn:ss format in my query. How do I do this taking into account Daylight Savings Time?
One way would be to use the free online converter at
http://www.epochconverter.com/
Here is a function
Good luck.Code:'The Unix date time stamp is the amount of seconds since '1970 / 01 / 01 12:00:00 am Function UnixTimeToDate(ByVal time_t As Long) As Date UnixTimeToDate = DateAdd("s", time_t, #1/1/1970#) End Function
Thanks for the code suggestion. Here is what I am finding:
Code I am using: DateSaved: DateAdd("s",[UnixDate],#12/31/1969 7:00:00PM#)
Here are my results:
1360162958 converts to 02/06/2013 10:02:38 <<<<< [is one hour fast]
1365698464 converts to 04/11/2013 11:41:04 <<<<< [is correct date and time]
Daylight Savings Time Change Over was 03/10/13
Any ideas why this is happening?
OK. AFter doing some research I have a solution to my problem. Here is the code I am using:
--------------------------------------------------
Public Function UnixToStdDateTime(varUnixInput As Variant) As Variant
Dim dteStart As Date, dteEnd As Date
If IsNull(varUnixInput) = False Then
UnixToStdDateTime = DateAdd("s", varUnixInput, #12/31/1969 7:00:00 PM#)
dteStart = DLookup("BeginDST", "tbl_DST", "intYear=" & Year(UnixToStdDateTime))
dteEnd = DLookup("EndDST", "tbl_DST", "intYear=" & Year(UnixToStdDateTime))
If UnixToStdDateTime < dteStart Or UnixToStdDateTime > dteEnd Then
' This date falls outside of daylight savings time. Subtract an hour.
UnixToStdDateTime = DateAdd("h", -1, UnixToStdDateTime)
End If
End If
End Function
--------------------------------------------------
But this method requires that I use a table with DST start and end dates. I would prefer that I don't have to use a DST table that I will have to update as the years go by. Can anyone help me with code that will do what I want without having to use a DST table?
Glad you have it resolved.
As for not using a DST table, if you're dealing with USA you could see if there is a way to apply the info at
http://www.timeanddate.com/worldcloc...one.html?n=179
Doesn't seem well-disciplined, especially after reading the wikipedia info at
https://en.wikipedia.org/wiki/Daylight_saving_time