Results 1 to 5 of 5

Thread: convert unix timestamp

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    buffalo
    Posts
    12

    convert unix timestamp

    is there a function that will convert a unix timestamp to a more conventional format? i am connecting to a unix server, which only provides me with a unix style timestamp. id like to format it like so:

    dd (month as text) yyyy but any other conventional format will do

  2. #2
    New Member
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    7
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    buffalo
    Posts
    12
    thanks, that did it

  4. #4
    New Member
    Join Date
    May 2003
    Posts
    12
    Just incase someone else stumbles across this thread...

    I was looking for similar info today. I found an old routine I'd written before, but I wasn't too certain of its results (I was worried about the 'non-day' portion of the conversion). Anyway, your function yeilds the same results as mine, so I was glad to see that, but I stumbled across something else interesting. Just out of curiousity I benchmarked the routine I had, and the one posted above (UnixTimeToDate). Results... after one million executions:

    UnixTimeToDate done in 34.2 seconds.
    UnixTimeToDate result : 3/13/2001 9:10:06 PM
    Long2Date done in 1.5 seconds.
    Long2Date result : 3/13/2001 9:10:06 PM

    Huge difference in performance! (Obviously calculating a date a million times isnt normal, but . . . *shrug* thats how performance goes, gain a slice here, a slice there... and in the end it starts to add up)

    So here are the routine(s) I have...

    Code:
    Private Function Long2Date(lngDate As Long) As Date
        Long2Date = lngDate / 86400# + #1/1/1970#
    End Function
    
    Private Function Date2Long(dtmDate As Date) As Long
       Date2Long = (dtmDate - #1/1/1970#) * 86400
    End Function

  5. #5
    New Member
    Join Date
    Feb 2013
    Posts
    1

    Re: convert unix timestamp

    Quote Originally Posted by Bradley2 View Post
    Just incase someone else stumbles across this thread...

    I was looking for similar info today. I found an old routine I'd written before, but I wasn't too certain of its results (I was worried about the 'non-day' portion of the conversion). Anyway, your function yeilds the same results as mine, so I was glad to see that, but I stumbled across something else interesting. Just out of curiousity I benchmarked the routine I had, and the one posted above (UnixTimeToDate). Results... after one million executions:

    UnixTimeToDate done in 34.2 seconds.
    UnixTimeToDate result : 3/13/2001 9:10:06 PM
    Long2Date done in 1.5 seconds.
    Long2Date result : 3/13/2001 9:10:06 PM

    Huge difference in performance! (Obviously calculating a date a million times isnt normal, but . . . *shrug* thats how performance goes, gain a slice here, a slice there... and in the end it starts to add up)

    So here are the routine(s) I have...

    Code:
    Private Function Long2Date(lngDate As Long) As Date
        Long2Date = lngDate / 86400# + #1/1/1970#
    End Function
    
    Private Function Date2Long(dtmDate As Date) As Long
       Date2Long = (dtmDate - #1/1/1970#) * 86400
    End Function


    Hello, I hope you are still around to help me with a, likely simple, problem. I'm trying to use your code to derive the date (in long string format), and then use it to create two mail messages. I'd like to use your code to get the date string, set it as a variable, and then reference that variable in each of my two messages. However, I'm not having any luck.

    Could you help get me started on this? Any help from anyone is much appreciate it.

    (I've tried just inserting "Date2Long", as below, and it gives an error.

    "Argument not option"

    ".Subject = "Auto-reply to: " & item.Subject & " - SR#: " & Date2Long & " has been created.""

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width