4 Replies Latest reply on Nov 11, 2015 6:38 AM by try67

    How to compare two dates in the validate event via Adobe Javascript?

    Alex Doubts Level 1

      I want to compare DOB  with Current date in the validate event.

      DOB should not be greater than current date. Tried below code. But not working.

      No value coming for nDate1 and nDate2.

      Code as follows:

       

      //Compare Date of Birth with Current Date

      app.alert(123);

      var dateformat = "dd/mm/yyyy";

      //Current Date

      var CurrentDate = util.printd(dateformat, new Date());

      //DOB Date Selected

      var DOB = event.value;

      //Date set to Current Date if Calendar Date is null

      if (DOB == "") {

          this.getField("DOB").value = util.printd(dateformat, new Date());

      }

      else {

          app.alert(DOB);

          app.alert(CurrentDate);

          var nDate1 = Date2Days(dateformat,CurrentDate);

          var nDate2 = Date2Days(dateformat, event.value);

          app.alert(nDate1);

          app.alert(nDate2);

          //If DOB Selected is greater than Current Date

          if ((nDate1 != "" && nDate2 != "") && nDate1 > nDate2) {

       

              app.alert("Date of Birth should not be greater than Current Date");

              this.getField("DOB").value = CurrentDate;

              this.getField("DOB").setFocus();

              exit();

          }

      }