3 Replies Latest reply on Sep 11, 2015 12:04 PM by gkaiseril

    Issue with getting a specific date to populate in a Form field

    bhinote81

      I have working Javascripts in place to automatically populate a Today field (to stamp the current date) and a Year field (to extract the current year from my system).

       

      What I'm having trouble finding is a script that will autopopulate a 3rd field with the static date of 12/31/yyyy where "yyyy" equals the Year field - 1.  For instance, if the Year field is populating to 2015, I'd like that 3rd field to automatically populate with 12/31/2014.

       

      Any help here is greatly appreciated.

       

      Thank you!

        • 1. Re: Issue with getting a specific date to populate in a Form field
          gkaiseril MVP & Adobe Community Professional

          So you have the current date in a field and you need to extract the just the year.

           

          And what is the script to populate the date field?

           

          Is this field updated each time the file is opened.?

           

          Sometimes one has to modify a script or write a new script.

          • 2. Re: Issue with getting a specific date to populate in a Form field
            bhinote81 Level 1

            Thanks for the response!  I'll try to be

             

            Here's the script for the Today field, which automatically stamps today's date in mm/dd/yyyy format on the file as soon as its opened:

             

            var f = this.getField("Today");

              f.value = util.printd

            ("mm/dd/yyyy", new Date());

             

            Here's my script for the Year field, which extracts the current year from my PC and automatically fills it in accordingly.  Right now, it populates the Year field with 2015 as soon as you open the file.  Next year, this document will start populating automatically with 2016, and so on.

             

            function Year() {

               var fld1 = this.getField

            ("Year");

               fld1.value = util.printd

            ("yyyy",new Date());

            }

            Year(); // call my function

             

            I just Googled these scripts and they both work swimmingly.  What I'm trying to do with this third field is take the current year from my PC and subtract it by 1 while also including it as the year portion of a static "12/31/yyyy" field where the year is the only part that changes when the file is opened.  So if the year is 2015, I'd like that field to populate with 12/31/2014.  In 2016, I'd like that field to populate as 12/31/2015.

             

            Thanks again!

            • 3. Re: Issue with getting a specific date to populate in a Form field
              gkaiseril MVP & Adobe Community Professional

              It appears Google did not  explain how they work nor where to find more about how to work with the code.

               

              The "new Date()" creates a date object with the current system date and time. This object has a value of the number of milliseconds since the Epoch date, January 1, 1970 midnight ad the Royal Observatory at Greenwich England. You system applies a time zone offset to get the local time and adjustment for day light savings time if needed. Through various computations a lot of data can be obtained from this object by using properties or methods. See the MDN JavaScript Reference for more information.

               

              The "util.date()" is a method to format the date object.

               

              Form the date object one can get the any unit of date or time and perform various computations on the date and have the correct date or time returned.

               

              Try as a document level script.

               

              // get the system date object;

              var oDate = new Date();

              // fill-in today's date field;

              this.getField("Today").value = util.printd

              ("mm/dd/yyyy", oDate);

              // compute the prior years value form the current year's full year method;

              this.getField("Year").value = oDate.getFullYear() - 1;