5 Replies Latest reply on Aug 14, 2013 12:02 PM by gkaiseril

    Date Field Problem

    sandy_88

      Hi everyone,

       

      Can anyone please resolve the below issues using javascript:

       

      User will enter the date in a text field, the date must be converted to mm/dd/yyyy format but there is condition for that date field, the date should be PRESENT or FUTURE DATE only, no date in the PAST can be used.

       

      Regards

      Sajeev

        • 1. Re: Date Field Problem
          gkaiseril MVP & Adobe Community Professional

          You have to use JavaScript to convert the date character string to the number of milliseconds from the epoch date for the inputted field and the current system time. Then you can compare the numeric values and if the inputted date value less than the current current date value then you have a problem.

          • 2. Re: Date Field Problem
            Akyron Level 1

            Example?

            • 3. Re: Date Field Problem
              gkaiseril MVP & Adobe Community Professional

              // custom vaildation scirpt for entered date being today or a future date;

              // date format for the field;

              var cDateFormat = "mm/dd/yyyy";

              // convert the entered value to a date objecta;

              var oEntered = util.scand(cDateFormat, event.value);

              // strip down to just the year, month and day

              oEntered.setFullYear(oEntered.getFullYear(), oEntered.getMonth(), oEntered.getDate());

              // convert todays date to a date object;

              oToday = util.scand(cDateFormat, util.printd(cDateFormat, new Date()));

              // strip down to just the year, month and day

              oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(), oToday.getDate());

              // compare the date values

              if(oEntered.getTime() < oToday.getTime()) {

              // error message date before today's date

              app.alert("Date must be today's date or a futuer date!", 1, 0);

              // set return code to error status;

              event.rc = false;

              }

              // validation is assumed to be true unless the event return code value is false;

              // end custom validation script;

              • 4. Re: Date Field Problem
                Akyron Level 1

                Thank you!

                • 5. Re: Date Field Problem
                  gkaiseril MVP & Adobe Community Professional

                  Be aware that this is for a from created with Acrobat and not LiveCycle Designer.