Solved

Converting Unix style timestamp to a Date in VB6.0

Posted on 2007-11-20
8
729 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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