25 Replies Latest reply on May 10, 2017 10:38 AM by try67

    Setting Date Range Validation in a Text field

    rakeshk21205956 Level 1

      I have a field called Text3 (date field with format mm/dd/yyyy) , and another field Text 4

       

      my condition are ,   user inputs any date in Text3 ... then  the Text4 default date will be  Text3 + 30 days, but the user can alter the Text 4 field with the range of Text3 to Text3 + 45 days ..

       

      For ex - If Text  3 = 01/01/2017,   then Text4 (default value) = 01/31/2017  but user can put any value (if he wants) in the range 01/01/2017  to 02/15/2017 i.e Text 3 +45 days

       

      Following is my script in put this in custom calculation tab:

       

      var sDate = this.getField("Text3").value; // get date string

      var oDate = util.scand("mm/dd/yyyy", sDate); // convert to object

      var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

      var nDate = oDate.getTime() + (30 * nDay); // add 7 days as milliseconds

      oDate = new Date(nDate); // convert milliseconds to date object

      defau= util.printd("mm/dd/yyyy", oDate); // format result

       

      var endDate = this.getField("Text3").value; // get date string

      var pDate = util.scand("mm/dd/yyyy", endDate); // convert to object

      var eDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

      var eDate = pDate.getTime() + (45 * eDay); // add 7 days as milliseconds

      pDate = new Date(eDate); // convert milliseconds to date object

      end= util.printd("mm/dd/yyyy", pDate); // format result

       

      var startDate = this.getField("Text3").value; // get date string

      stDate = util.scand("mm/dd/yyyy", startDate); // convert to object

       

      if (stDate <= event.value <= end) {event.value = event.value}

      else { event.value = defau}

       

       

       

       

      But somehow this is not working...... .. plz help..