4 Replies Latest reply on Aug 10, 2006 7:30 AM by Newsgroup_User

    How to match dates(Greater OR Less)

    AntiTRUST�

      Hi All,
      I need to know how can i match two different dates?? in date formats.
      Like i have one date of "15-08-06" and the otherone is "21-10-06". So, how can i get the
      difference that the date is greater then or less then.

      I tried to make it integer and then match the dates but that procedure is not OK with respect
      to my task.

      So, i need some help on this.

      Thanks in advance.
      Amir
        • 1. Re: How to match dates(Greater OR Less)
          Level 7
          Try converting your dates into #date objects. You can then subtract one
          from the other. You'll need to parse your current string representation,
          perhaps using "-" as the itemDelimiter.
          For example:
          the itemDelimiter = "-"
          d1 = date(integer(d1.item[3]), integer(d1.item[2]), integer(d1.item[1]))
          d2 = date(integer(d2.item[3]), integer(d2.item[2]), integer(d2.item[1]))
          nDiff = d2 - d1
          put nDiff
          • 2. Re: How to match dates(Greater OR Less)
            AntiTRUST� Level 1
            Hi Sean,
            Thanks for the reply. Basically this is what i have already done, but this thing basically doesn't compare, i need to compare two different dates, like they are equal or greater or less then.


            Any idea?
            Amir
            • 3. Re: How to match dates(Greater OR Less)
              Lukewig Level 1
              Hi,

              Like Sean says, convert your 'date' strings into date objects and then you can subtract one from the other or do simple comparisons. Eg

              dateObject1 = date("20060815")
              dateObject2 = date("20061021")
              put dateObject1 = dateObject2
              put dateObject1 < dateObject2
              put dateObject1 > dateObject2

              Luke
              • 4. Re: How to match dates(Greater OR Less)
                Level 7
                If all else fails, you can do a simple formula to convert each date into a
                single value.

                dateValue1 = (year1 * 366) + (month1 * 31) + days1
                dateValue2 = (year2 * 366) + (month2 * 31) + days2

                Then just compare dateValue1 and dateValue2. This formula leaves gaps at
                the end of some months, and all non-leap years, but for the sake of a simple
                greater/less than comparison, these don't matter. (If you needed to be more
                precise, you'd have to refine the formula somewhat, but the simple version
                works fine for just >/< calcs.)