6 Replies Latest reply on Jun 27, 2013 6:04 AM by try67

    Date calculation

    Formzet - Zoetermeer Level 1

      I have two fields with custom formatting (keystroke script for numbers only)

      And a validation to validate the input as a date (ddmmyyyy) (customer wants a different error message)

       

      Now i want to check if date 1 is older then date 2

      But i doesn't get it to work.

      I get the folowing error: "TypeError: vDateInput2 is null"

       

      i tried the folowing:

       

      event.rc = true;
      
      
      if (event.value) {
                if (util.scand("ddmmyyyy", event.value)==null) {
                          app.alert("Wrong date");
                          event.rc = false;
                          event.target.setFocus();
                }
                else{
                          var vDate1 = event.value;
                          var vDate2 = this.getField("DateField1").value;
      
      
                          var vDateInput1 = util.scand("ddmmyyyy",vDate1);
                          var vDateInput2 = util.scand("ddmmyyyy",vDate2);
      
      
                          var diff = vDateInput2.getTime() - vDateInput1.getTime();
      
      
                          if(diff < 0){
                                    app.alert("Wrong date. Date 1 must be older than Date 2");
                                    event.rc = false;
                                    event.target.setFocus();
                          }
                }
      }