Announcement

Collapse
No announcement yet.

Problem with date evaluation

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

  • Problem with date evaluation

    I am reading an "effective date" from an INI file, the date is in the format mm/dd/yyyy. I want to compare the effective date to the date when the AMS4 executable is run and display a warning whenever the executable is run before the date in the INI file. For example, if the AMS4 executable is run before the "effective date" of 12/17/2003, I want the warning to show.

    This is what I currently have: %effectivedate% = 12/17/2003

    IF (%DATE% < %effectivedate%)
    %Result% = Dialog.MessageBox ("Message", "%DATE% is earlier than %effectivedate%", Ok, Information)
    END IF

    The correct message I am getting is "09/15/2003 is earlier than 12/17/2003". Now, if I change the effective date to 12/17/2000, I still get "09/15/2003 is earlier than 12/17/2000" and this is incorrect. Am I doing something wrong?



  • #2
    Re: Problem with date evaluation

    You can't compare date strings that way. If you want to be able to compare them, either use ISO-style dates (YYYYMMDD) that can be compared alphabetically, or use Julian dates so you can perform a numeric comparison.
    --[[ Indigo Rose Software Developer ]]

    Comment


    • #3
      Re: Problem with date evaluation

      Well it seems to be comparing just the first numbers, i.e. 9 and 12 so I would assume you are trying to treat a string as an integer... If it were me I'd split up the date into substrings use a DELIMITED STRING section and then compare the 3 pieces seperately starting with year and then going to month and then day.

      Corey Milner
      Creative Director, Indigo Rose Software

      Comment


      • #4
        Re: Problem with date evaluation

        It isn't treating them as integers, Corey. Just doing an alphabetical comparison. The string "09/15/2003" is alphabetically lower than "12/17/2000." For the same reason "00500" comes before "3."

        In order to perform relational comparisons between two dates using a string comparison, they need to be in a format that can be sorted alphabetically.
        --[[ Indigo Rose Software Developer ]]

        Comment


        • #5
          Re: Problem with date evaluation

          Oh I see. Ok I read wrong.

          Corey Milner
          Creative Director, Indigo Rose Software

          Comment


          • #6
            Re: Problem with date evaluation

            How can I convert a date (other than today's date) to Julian?

            For the alternative using ISO dates, I was able to use your suggestion to convert mm/dd/yyyy into ISO Date format. Does it matter if I have non-numerical characters in between ( ie dash or slash )?

            This is how I formatted the date:

            %year% = String.GetDelimitedString ("%effective%", "/", 2)
            %month% = String.GetDelimitedString ("%effective%", "/", 1)
            %day% = String.GetDelimitedString ("%effective%", "/", 0)
            %effectiveISO% = "%year%-%month%-%day%"

            Is there a better way than how I did it?

            Thanks!

            Comment


            • #7
              Re: Problem with date evaluation


              How can I convert a date (other than today's date) to Julian?
              No easy way to do that dynamically, unfortunately. You could temporarily set your system date to the date you want, and then grab the Julian date for "today." Or you could calculate it from a given date, if you knew how many days had elapsed since.

              Or you could use the same algorithm that we use to calculate the dates.

              ISO dates are superior, IMO, because you can actually read them -- so long as you are only performing comparisons on the dates, and aren't using them in any mathematical calculations (like subtracting 30 from them or something).


              Does it matter if I have non-numerical characters in between ( ie dash or slash )?
              No. They'll work the same either way. Technically, the comparison methods will change a bit internally, but the end result should be the same. Worth testing, though, just to be sure. [img]/ubbthreads/images/icons/wink.gif[/img]

              I would recommend leaving the non-numeric characters in there, just so you don't mistake the dates as Julian dates or regular numbers (and try to perform calculations on them).


              This is how I formatted the date:

              %year% = String.GetDelimitedString ("%effective%", "/", 2)
              %month% = String.GetDelimitedString ("%effective%", "/", 1)
              %day% = String.GetDelimitedString ("%effective%", "/", 0)
              %effectiveISO% = "%year%-%month%-%day%"

              Is there a better way than how I did it?
              No, you used a very smart method of splitting the string into pieces. Very nicely done, in fact. [img]/ubbthreads/images/icons/smile.gif[/img]

              You can use the System - Get Date Time action to retrieve the current date in ISO format.
              --[[ Indigo Rose Software Developer ]]

              Comment


              • #8
                Re: Problem with date evaluation

                Lorne,

                I am currently using your suggestion for the current date, but for "This is how I formatted the date:" I meant the date I read from the INI file which is in the standard format mm/dd/yyyy. The way I implemented it (per Corey's suggestion) works fine and is simple enough, but I am just curious if it can be done another way. I like to learn new tricks!

                By the way, thanks for your reply!

                Comment


                • #9
                  Re: Problem with date evaluation

                  I found a mistake in my code.

                  I had:

                  %year% = String.GetDelimitedString ("%effective%", "/", 2)
                  %month% = String.GetDelimitedString ("%effective%", "/", 1)
                  %day% = String.GetDelimitedString ("%effective%", "/", 0)
                  %effectiveISO% = "%year%-%month%-%day%"

                  It should be:

                  %year% = String.GetDelimitedString ("%effective%", "/", 2)
                  %month% = String.GetDelimitedString ("%effective%", "/", 0)
                  %day% = String.GetDelimitedString ("%effective%", "/", 1)
                  %effectiveISO% = "%year%-%month%-%day%"

                  Comment


                  • #10
                    Re: Problem with date evaluation

                    Ah, good catch.
                    --[[ Indigo Rose Software Developer ]]

                    Comment

                    Working...
                    X