Consulting

Results 1 to 9 of 9

Thread: Date conversion from Linux format

  1. #1
    VBAX Regular
    Joined
    Jun 2004
    Location
    Los Angeles
    Posts
    22
    Location

    Question Date conversion from Linux format

    Hi all,

    I'm looking to see if anyone has already created a macro for conversion of linux timestamps into excel dates...

    Linux times (as least on our linux network) is expressed as seconds since "00:00:00 Janurary 1, 1970".

    Whereas Excel expresses dates as days since Janurary 1, 1900.

    I'm working with database output from a linux server, and my dates are in Linux units.

    Anyone done this already?

    -Blakieto

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you post a workbook with some of the Linux outputs?

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    This formula should work for this conversion.
     =DATE(1970,1,1) + A1/86400
    Where A1 houses the Linux date in seconds.
    A1/86400 will give the total number of days.
    Then we add that to the start date of 1/1/1970.

  4. #4
    VBAX Regular
    Joined
    Jun 2004
    Location
    Los Angeles
    Posts
    22
    Location

    almost correct...

    Interesting... I would have thought that DRJ's formula would work. However, it appears to be off by a fraction of a day.

    I've attached a workbook with three columns: the provided linux timestamps, conversion via DRJ's formula and a column of the correct dates and times.

  5. #5
    VBAX Regular
    Joined
    Jun 2004
    Location
    Los Angeles
    Posts
    22
    Location
    By subtracting a half day from Jacob's formula, the correct answer is produced. The final formula is:

    =DATE(1970,1,1) + (A1 - 43600)/86400

    Thanks!

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I am not sure why you would have to suptract half a day unless the linux time started at 12PM on 1/1/1970?

    Glad you got it working.

    Take Care

  7. #7
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Does Linux works always on that date system or is it a particular thing from this system??
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  8. #8
    VBAX Regular
    Joined
    Jun 2004
    Location
    Los Angeles
    Posts
    22
    Location

    reply to Paleo

    I believe that most linux systems use this time system. This is also called "coordinated universal time (UTC)". The linux command "localtime" receives time in these units and converts into human readable text. So it seems to be built in...

  9. #9
    VBAX Regular
    Joined
    Jun 2004
    Location
    Los Angeles
    Posts
    22
    Location
    After a bit of use, I find that what I posted as the correct formula was not correct. Rather than subtracting 12 hours during the conversion, there should be 8 hours subtracted:

    =DATE(1970,1,1) + (A1 - 28800)/86400

Posting Permissions

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