Solved

Converting Unix style timestamp to a Date in VB6.0

Posted on 2007-11-20
8
706 Views
Last Modified: 2008-02-01
Hi:

I need to be able to convert a Unix style time stamp (ms since 1/1/1970) to a date in vb 6.0.

Dim dblMilliseconds as double
dblMilliseconds = "some timestamp value"

I've got a client waiting on this, so I have to resolve it quickly.

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 63 total points
ID: 20322096
0
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 62 total points
ID: 20322110
Option Explicit

Private Sub Command1_Click()
    MsgBox DateFromUnix(1195584810)
End Sub

Private Function DateFromUnix(lngTimestamp As Long) As Date
    DateFromUnix = DateAdd("s", lngTimestamp, #1/1/1970#)

End Function
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20322138
The standard Unix timestamp is seconds since 1/1/1970.  For milliseconds, it would take a minor adjustment:

Option Explicit

Private Sub Command1_Click()
    MsgBox DateFromUnix(1195584810000#)
End Sub

Private Function DateFromUnix(dblTimestamp As Double) As Date
    DateFromUnix = DateAdd("s", dblTimestamp / 1000, #1/1/1970#)

End Function
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:cup
ID: 20323097
Windows timestamps are also from 1/1/1970.  Time is stored as a float.  Just multiply by 86400000.  The time now would be


cdbl(now) * 86400000
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20323581
>Windows timestamps are also from 1/1/1970.  Time is stored as a float.  Just multiply by 86400000.  The time now would be

In VB, the date data type maps internally to a double floating point value.  The days are stored in the integer part and the time of day is stored in the fractional part.

Debug.Print CDbl(Now)

yields:

39406.6760185185

That's the number of days since 12/30/1899
0
 
LVL 11

Expert Comment

by:cup
ID: 20326075
Oops - I was playing with VBScript.   Sorry.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20328085
It works the same in VBScript.  
0
 
LVL 11

Expert Comment

by:cup
ID: 20331870
So it should have been

(cdbl(now) - cdbl(#1/1/1970#)) * 86400000

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question