4 Replies Latest reply on Oct 14, 2015 11:12 AM by gkaiseril

    Add 44 days to today's date and display dd mmmm yyyy

    glennh50606799 Level 1

      I have created a form in Acrobat Pro DC and I need a form field to display the date 44 days from the day the form is filled out.  Have searched these forums and found answers that are close but they all seem to calculate based on another field in the document.  I don't have the current date on the form and I'm javascript 'challenged' so can't work it out.

       

      So when the user opens the form today (13 October 2015) the from field should display 26 November 2015.

       

      Thanks in advance for your help.

        • 1. Re: Add 44 days to today's date and display dd mmmm yyyy
          glennh50606799 Level 1

          From this post Working with date and time in acrobat JavaScript help request...

           

          I changed the days so it looks like this...

           

          // get the number of milliseconds from the current date object;

          var rightNow = (new Date()).getTime();

          // define 44 days in milliseconds;

          var fortyfourDays = 44 * 24 * 60 * 60 * 1000;

          // add 44 days to the value of right now and assign the result to final time;

          var finalTime = rightNow + fortyfourDays;

          // convert the finalTime value to a date object;

          var theNewDate = new Date(finalTime);

          // display the result;

          console.println("44 days from now is: " + theNewDate.toString());

           

          This calculates perfectly in the console window.  Now I just need to find out how to get it to display in the form field...

          • 2. Re: Add 44 days to today's date and display dd mmmm yyyy
            gkaiseril MVP & Adobe Community Professional

            Another approach would be to use JavaScript's getDate() and setDate() methods for the date object.

             

            // get the current date object;

            var oNow = new Date();

            // new date object

            var oNew = new Date();

            // get the current date from the date object;

            var nNowDate = oNow.getDate();

            // add 44 days to the current date;

            var nNewDate = nNowDate + 44;

            // update new date object;

            oNew.setDate(nNewDate);

            // format the new date object text string;

            var cNewDate = util.printd("dd mmmm yyyy", oNew);

            // set field value;

            event.value = cNewDate;

            // show some information;

            console.show();

            console.clear();

            console.println("Today is : " + util.printd("dd mmmm yyyy", oNew));

            console.println("Today's date is: " + oNow.getDate());

            console.println("Today's date = 44 days: " + nNewDate);

            console.println("44 days from now is: " + cNewDate);

             

            The script could be more compact by combining several lines of code into one line of code:

             

            // get the current date object;

            var oNow = new Date();

            // add 44 days to the current date;

            oNow.setDate(oNow.getDate() + 44);

            // set field value;

            event.value = util.printd("dd mmmm yyyy", oNow);

            • 3. Re: Add 44 days to today's date and display dd mmmm yyyy
              glennh50606799 Level 1

              Thanks G, that works perfectly.  Just out of interest is it the 'console.show()' that actually outputs the result to the form field rather than just being visible in the debugger console?

              • 4. Re: Add 44 days to today's date and display dd mmmm yyyy
                gkaiseril MVP & Adobe Community Professional

                "console.show()" only opens the JavaScript console so any messages sent tot he console device can be viewed. It was used to show the interim results during the calculation. I prefer to use the getDAys/setDays since using the milliseconds for a unit like a day or longer is at best an estimate since a year is almost 365.2425 days and most users would use 365.25. The difference between using the day count and the estimated value becomes evident around the 100 year mark.