Results 1 to 7 of 7

Thread: How to convert a Date in to an integer?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    6

    How to convert a Date in to an integer?

    How do i convert a Date into an Integer?
    From this format: 12/03/2014
    To this format: 41710
    is there a function i can use?
    and how would i get it back to this format: 12/03/2014
    from this format: 41710

    Thank you

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: How to convert a Date in to an integer?

    There is no link between 12/03/2014 to 41710 -__-
    If you mean from 12/03/2014 to 120314 or 120032014 Then Convert it into a string and replace \ with nothing and convert that to an Integer.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    6

    Re: How to convert a Date in to an integer?

    http://stackoverflow.com/questions/1...date-to-number

    this is what im trying to achieve

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: How to convert a Date in to an integer?

    I believe there are two functions that might do what you are looking for. Take a look at this link:

    http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
    My usual boring signature: Nothing

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to convert a Date in to an integer?

    Have you tried, FromOADate and ToOADate ?

    Code:
    ' convert Integer to Date
    Debug.WriteLine(DateTime.FromOADate(41710)) ' 3/12/2014 12:00:00 AM
    
    ' convert a Date into an Integer
    Dim myDate = New Date(2014, 3, 12)
    Debug.WriteLine(myDate.ToOADate) ' 41710

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: How to convert a Date in to an integer?

    there really isn't a "formula" ... that IS the date. it's in a different format is all. The number behind the date is calculates as the number of _______ since _________. And it varies from system to system. I think it's determined by the number of minutes since 1/1/1900... for Linux systems it's since some date in 1963.

    for the case given the date in the link, it's the number of days since 1/1/1900...
    Name:  vbfTotalDays.JPG
Views: 193
Size:  22.1 KB


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: How to convert a Date in to an integer?

    Actually, I got a different number from what Excel reported (41579) ... hmm... that's off by quite a bit some 290 days...
    Ahh.... 41579 days would be Nov 3, 2013 ... so there's potential date formatting issues to be resolved.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width