Results 1 to 5 of 5
  1. #1
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51

    Unix TimeStamp Conversion Question

    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?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    One way would be to use the free online converter at
    http://www.epochconverter.com/

    Here is a function
    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
    Good luck.

  3. #3
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    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?

  4. #4
    rmoreno is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2013
    Posts
    51
    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?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    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

Please reply to this thread with any new information or opinions.

Similar Threads

  1. In need of UNIX text files for testing.
    By rpeare in forum Import/Export Data
    Replies: 2
    Last Post: 11-06-2012, 09:25 AM
  2. Insert A TimeStamp
    By dandoescode in forum Forms
    Replies: 3
    Last Post: 06-25-2012, 12:34 PM
  3. Passthrough over a timestamp?
    By KrisDdb in forum Access
    Replies: 1
    Last Post: 01-10-2012, 06:42 PM
  4. Converting UNIX time
    By sharon.chapman7 in forum Programming
    Replies: 3
    Last Post: 09-02-2011, 08:32 AM
  5. Unix Time
    By wifor in forum Programming
    Replies: 2
    Last Post: 07-29-2008, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums