Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How do I convert to and from UNIX standard epoch date numbers?

How do I convert to and from UNIX standard epoch date numbers?

Scheduled Pinned Locked Moved Visual Basic
questionperlhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Olle Jonsson
    wrote on last edited by
    #1

    This is my first time here, so: hi guys! Hope your day does not suck. Mine is OK, but I'm banging my fragile head against a problem with converting UNIX standard epoch numbers to something fairly regular, date-wise. I receive a timecode from a Perl program, written as seconds since 1970, the standard way of talking about time in the UNIX world. Then my VB component wants to log this thing, and well, I'd like to be able to record it like YYYY-MM-DD HH:MM, but so far I am stumped. Some gotchas (add to this list if you can come up with more difficulties that could crop up during the writing of such a function): * leap years A few examples of timecodes from the last few weeks: 1054746806 1054555725 1056715898 OK, that is my question. Have you done this before? Have a nice day, folks. Olle Lund, Sweden

    M O 2 Replies Last reply
    0
    • O Olle Jonsson

      This is my first time here, so: hi guys! Hope your day does not suck. Mine is OK, but I'm banging my fragile head against a problem with converting UNIX standard epoch numbers to something fairly regular, date-wise. I receive a timecode from a Perl program, written as seconds since 1970, the standard way of talking about time in the UNIX world. Then my VB component wants to log this thing, and well, I'd like to be able to record it like YYYY-MM-DD HH:MM, but so far I am stumped. Some gotchas (add to this list if you can come up with more difficulties that could crop up during the writing of such a function): * leap years A few examples of timecodes from the last few weeks: 1054746806 1054555725 1056715898 OK, that is my question. Have you done this before? Have a nice day, folks. Olle Lund, Sweden

      O Offline
      O Offline
      Olle Jonsson
      wrote on last edited by
      #2

      After doing a nice function to calculate how many seconds have elapsed since 1970-01-01 00:00:00 a workmate came by and whistled that I should do a DateDiff() DateDiff("s", CDate("1970-01-01 00:00:00"), Now) Which was correct. Sigh. I'll try and make the other conversion, now. From seconds into days and years and months and... See you. Olle, Shamed in a corner, Lund, Sweden

      1 Reply Last reply
      0
      • O Olle Jonsson

        This is my first time here, so: hi guys! Hope your day does not suck. Mine is OK, but I'm banging my fragile head against a problem with converting UNIX standard epoch numbers to something fairly regular, date-wise. I receive a timecode from a Perl program, written as seconds since 1970, the standard way of talking about time in the UNIX world. Then my VB component wants to log this thing, and well, I'd like to be able to record it like YYYY-MM-DD HH:MM, but so far I am stumped. Some gotchas (add to this list if you can come up with more difficulties that could crop up during the writing of such a function): * leap years A few examples of timecodes from the last few weeks: 1054746806 1054555725 1056715898 OK, that is my question. Have you done this before? Have a nice day, folks. Olle Lund, Sweden

        M Offline
        M Offline
        Matt Casto
        wrote on last edited by
        #3

        I believe this will work, but I didn't actually test it against any known Epoch date values. Private Function GetEpochDate(ByVal seconds As Long) As DateTime   Dim BeginningOfTime As New DateTime(1970, 1, 1)   Return BeginningOfTime.AddSeconds(seconds) End Function

        O 1 Reply Last reply
        0
        • M Matt Casto

          I believe this will work, but I didn't actually test it against any known Epoch date values. Private Function GetEpochDate(ByVal seconds As Long) As DateTime   Dim BeginningOfTime As New DateTime(1970, 1, 1)   Return BeginningOfTime.AddSeconds(seconds) End Function

          O Offline
          O Offline
          Olle Jonsson
          wrote on last edited by
          #4

          I regret that I am now working with VB6, and I'm also sorry I didn't include that into my first posting. I bow my head in shame. DateAdd() is my next stop, I guess. Yep, it was! Public Function GetEpochToDate(ByVal seconds As Long) As Date   GetEpochDate = DateAdd("s", seconds, CDate("1970-01-01 00:00:00")) End Function Public Function GetDateToEpoch(ByVal theDate As Date) As Long   GetDateToEpoch = DateDiff("s", CDate("1970-01-01 00:00:00"), theDate) End Function Thank you, Matt!

          A 1 Reply Last reply
          0
          • O Olle Jonsson

            I regret that I am now working with VB6, and I'm also sorry I didn't include that into my first posting. I bow my head in shame. DateAdd() is my next stop, I guess. Yep, it was! Public Function GetEpochToDate(ByVal seconds As Long) As Date   GetEpochDate = DateAdd("s", seconds, CDate("1970-01-01 00:00:00")) End Function Public Function GetDateToEpoch(ByVal theDate As Date) As Long   GetDateToEpoch = DateDiff("s", CDate("1970-01-01 00:00:00"), theDate) End Function Thank you, Matt!

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            nice

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups