|
-
Jul 3rd, 2002, 06:41 PM
#1
Thread Starter
New Member
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
-
Jul 5th, 2002, 03:20 AM
#2
New Member
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
-
Jul 7th, 2002, 12:07 AM
#3
Thread Starter
New Member
-
May 17th, 2003, 11:39 PM
#4
New Member
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
-
Feb 4th, 2013, 11:56 AM
#5
New Member
Re: convert unix timestamp
 Originally Posted by Bradley2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|