Read/Write TimeStamp In Seconds from Certain Date

Posted on 2007-08-01
Last Modified: 2010-04-30
I have software that writes a time stamp in seconds starting from the date 01/01/1970 00:00:00
Example this is the Date 07/31/2007 16:44:44 and the TimeStamp is 1185900284
The time stamp is the seconds that have passed from the date above, I'm trying to figure out how to read the time stamp to get the date and read the date to get the time stamp.
Question by:thaburner
    LVL 92

    Accepted Solution

    Hello thaburner,

    MsgBox DateAdd("s", #1 Jan 1970#, TimeStamp)   < --- convert time stamp to date
    MsgBox DatDiff("s", #1 Jan 1970#, Now)                 < --- convert date to time stamp


    LVL 38

    Assisted Solution

    Option Explicit

    Private Sub Command1_Click()
        MsgBox DateFromTimestamp(1185900284)
        MsgBox TimeStampFromDate(DateFromTimestamp(1185900284))
    End Sub

    Private Function DateFromTimestamp(TimeStamp As Long) As Date
        DateFromTimestamp = DateAdd("s", TimeStamp, #1/1/1970#)
    End Function

    Private Function TimeStampFromDate(dt As Date) As Long
        TimeStampFromDate = DateDiff("s", #1/1/1970#, dt)
    End Function


    Author Comment

    That worked perfectly thanks....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    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…
    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…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now