Compare 2 date fields


#1

I need help comparing 2 date fields. I have 2 requirements:

  1. Date entered in Date2 box must not be before Date entered in Date1 box else display an error message.
  2. Date 2 must be 30 days after Date1, else generate an error

My file is attached.DateVal.rp (44.8 KB)

Please help


#2

See Page 2 of this updated file for a solution:
DateVal.rp (64.6 KB)

When comparing dates, you need to convert a date to a single number, which you can then use in math equations. The number of milliseconds since “UNIX birth” is the standard. In Axure, you can get this from one of two built-in functions: Date.parse(myDate) or myDate.getTime() , where “myDate” is a valid date string–like the value of a Text Field set to input type: Date.

However, there is a long-standing bug in Axure in which (the value of) Text Field widgets set to “Date” type are unusable, unless you first remove any “Hint Style” from the Style Effects (found on the INTERACTIONS pane) --see this thread for details:

So here is what I did on Page 2:

  • Removed “Hint Style” from both text fields
  • Added an “Error Message” group, and set it to hidden
  • Added a “goodToGo” checkmark shape, and set it to hidden
  • Added two “Box 2” widgets just to demonstrate the “elapsed milliseconds” of each date field (these are not necessary)
  • Created 4 conditional cases for the Compare button
    • Case 1 (if Date 2 is before Date 1)
      • The condition is “If [[D2.getTime()]] is less than [[D1.getTime()]]”
        • D2 is a pointer (local variable expression) to the text on the Date2 widget. Likewise for D1
        • Each expression (wrapped by double-brackets) converts the date to milliseconds for an easy math equation here
      • Because your first requirement is a subset of your second requirement, it is not really needed, unless you want to vary the error message just to handle this …so I did that.
    • Case 2 (if Date 2 is less than 30 days after Date 1)
      • Here I compare the difference between Date 2 and Date 1 to the number of milliseconds in 30 days. To calculate 30 days worth of milliseconds, I use 1000 (number of ms in one second) times 60 (number of seconds in a minute) times 60 (minutes in an hour) times 24 (hours in a day) times 30 (days)
      • Again, I change the text of the error message. This one error message string should work well for both of your requirements though, I think.
    • Case 3 (if Date 2 is at least 30 days after Date 1)
      • If so, success
      • I show a green checkmark widget just for good feedback here
    • Case 4 (if true; for demonstration purposes only)
      • Sets text of the gray boxes to the “elapsed milliseconds” values of the date fields
      • (Because it is an “If true” condition, it will always get fired, regardless the outcome of other conditional cases)