Announcement

Collapse
No announcement yet.

Easy way to do a DATE comparison?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Easy way to do a DATE comparison?

    Hey all,

    Is there an easy way to do a date comparison if the dates are in
    string format? (ie. Is "01/01/2001" less than "02/14/2001")

    I'm afraid the long answer is to parse out each date, add the date parts
    to a SYSTEMTIME struct, convert the SYSTEMTIME struct to a FILETIME
    struct, and then use the CompareFileTime Windows API function to
    get my answer.

    Any ideas would be much appreciated. Thanks!

    Scott



    ------------------
    Scott Wolfington
    http://www.boogietools.com



    [This message has been edited by Scott Wolfington (edited March 05, 2003).]
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

  • #2
    Scott,

    Use a Julian function. See the download section of my website.


    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

    Comment


    • #3
      I emailed you my checkreg.bas file, it has everything you will need.




      Scott


      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        Scott W. --

        All of those suggestions will work, or, if you want to keep it simple, you could just
        write a function that converts the strings to a format that can be compared directly.

        01/01/2001 --> 20010101
        02/14/2001 --> 20010214

        If you place the elements of the date in "descending" order a normal string comparison
        can be performed.

        This logic can be extended to compare date/times too, using YYYMMDDHHMMSS. Be careful
        if you use VAL to convert a date/time in that format to a numeric value, because it
        will overflow a LONG in the year 2147. Use a DWORD instead. But there's really no
        reason to use VAL when the strings can be compared directly, unless using VAL and
        a numeric comparison is faster than a string comparison. (I haven't checked.)

        -- Eric
        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>



        [This message has been edited by Eric Pearson (edited January 18, 2001).]
        "Not my circus, not my monkeys."

        Comment


        • #5
          Do yourself a favour....
          Create your date-routine around 'VARIANT TIME' (same as VB-date/time)
          and you will be able to 'do math' on them.
          Add a day,second or year...


          ------------------
          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Comment


          • #6
            Thanks everyone for your prompt responses. I definitely have some stuff
            to try out now. Right off the bat, I like Eric's approach the best.
            It seems the quickest, although I haven't spent much time poking holes
            in this approach. Doesn't seem like there are any though.

            Thanks for the email Scott T.

            Regards,
            Scott


            ------------------
            Scott Wolfington
            http://www.boogietools.com


            [This message has been edited by Scott Wolfington (edited March 05, 2003).]
            Scott Wolfington
            [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

            Comment

            Working...
            X