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. Convert to Date

Convert to Date

Scheduled Pinned Locked Moved Visual Basic
question
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.
  • N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #1

    How can i convert a 5 digit number to date e.g. 05120 to 4/30/2005

    D 1 Reply Last reply
    0
    • N nitin_ion

      How can i convert a 5 digit number to date e.g. 05120 to 4/30/2005

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Since I don't know of any 5 digit numbers that represents a date, what does this number represent? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Since I don't know of any 5 digit numbers that represents a date, what does this number represent? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        N Offline
        N Offline
        nitin_ion
        wrote on last edited by
        #3

        it actually a julian date format 10204120 all i need is to be able to convert last three digits 325 into months and day format in this case it's 04/31

        C D 2 Replies Last reply
        0
        • N nitin_ion

          it actually a julian date format 10204120 all i need is to be able to convert last three digits 325 into months and day format in this case it's 04/31

          C Offline
          C Offline
          cwayman
          wrote on last edited by
          #4

          Hey this should do it

              Dim JulDate As Long
              Dim TempDate As String
              Dim FinalDate As Date
              JulDate = 100015 'Your Julian Date
          
              TempDate = "01/01/"
          
              If JulDate > 99999 Then
                  TempDate = TempDate + Mid(LTrim(Str(JulDate)), 2, 2)
              Else
                  TempDate = TempDate + Mid(LTrim(Str(JulDate)), 2)
              End If
          
              FinalDate = DateAdd("d", Val(Mid(Str(JulDate) - 1, 3)), TempDate)
          

          then use

          Debug.WriteLine(FinalDate, Format(FinalDate, "mm/dd/yyyy"))

          or

          MsgBox(FinalDate)

          to output it to screen so...

          Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim JulDate As Long
              Dim TempDate As String
              Dim FinalDate As Date
              JulDate = 100015 'Your Julian Date
          
              TempDate = "01/01/"
          
              If JulDate > 99999 Then
                  TempDate = TempDate + Mid(LTrim(Str(JulDate)), 2, 2)
              Else
                  TempDate = TempDate + Mid(LTrim(Str(JulDate)), 2)
              End If
          
              FinalDate = DateAdd("d", Val(Mid(Str(JulDate) - 1, 3)), TempDate)
          
              MsgBox(FinalDate)
          
          End Sub
          

          should do it for you. Hope this helps Chris

          1 Reply Last reply
          0
          • N nitin_ion

            it actually a julian date format 10204120 all i need is to be able to convert last three digits 325 into months and day format in this case it's 04/31

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            "Julian" dates are a representation of the number of days since a base date. In Excel for Windows, this would be Jan 1, 1900 (for the Mac, it would be Jan 1, 1904). These numbers are really just serial numbers, but what date this number represents is entirely up to the application/system that issued it. The .NET Framework uses a structure that can represent any date/time from midnight on Jan 1, 0001 to Midnight Dec 31, 9999, measured in ticks (100 milliseconds). You can use this structure to try and parse your date/time number into a .NET Framework date/time, then get the month and day from that. Look into DateTime.FromOADate (OLE Automation dates), and DateTime.FromFileTime (filesystem date/time format). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            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