7 Replies Latest reply on Jun 10, 2015 9:42 AM by Branchard0902

    Date Formats

    Branchard0902 Level 1

      Hi - I'm having some problems.


      I've got my date field completed and it pulls in the format 06/10/2015.

      But I have two other fields. I need one to only pull the day and the other to only pull the month.

      I thought I had it worked out but all the sudden its not working.


      Please help!

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

          And how did you work it out?


          I would convert the date string from the field into a JavaScript date object, and then use the various methods of the date object to get the value of the day and the month or if I needed the month in alphabetical characters I would use the util.printd method.


          // get the field value;

          var cDate = this.getField("MyImputDate").valueAsString;
          // convert the date string to a date object;

          var oDate = util.scand("mm/dd/yyyy", cDate);

          // extract the date from the date object;

          var nDate = oDate.getDate();

          // extract the month form the date object (zero base value);

          var nMonth = oDate.getMonth() + 1;

          // report the results;

          app.alert("Input date: " + cDate +

          "\nDate: " + nDate +

          "\nMonth: " + nMonth, 3, 0);


          • 2. Re: Date Formats
            Branchard0902 Level 1

            I'm sorry but I'm really confused.


            I already have a field that automatically pulls in the current date with the following script:

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

            f.value = util.printd("mm/dd/yyyy", new Date());


            Now I have created a new field that I need to pull just the "DD" for.

            And then another field I need to pull the "MMM" for.

            Does that make sense?

            • 3. Re: Date Formats
              Karl Heinz Kremer Adobe Community Professional

              If you just want the day and month of the current date/time, you can use the same script that you've used before, just with a different formatting string:


              var f = this.getField("DateMMM");
              f.value = util.printd("mmm", new Date());



              var f = this.getField("DateDD");
              f.value = util.printd("dd", new Date());

              The formatting strings are lower case, and not capitals as you’ve specified them. You can get all the details here: http://help.adobe.com/livedocs/acrobat_sdk/11/Acrobat11_HTMLHelp/wwhelp/wwhimpl/common/htm l/wwhelp.htm?context=Acrobat11…


              Keep in mind that if you combine the three snippets into one, you only have to declare the variable f once, so only use "var f = ..." in one place and then "f = ..." for the second and third instance.

              • 4. Re: Date Formats
                gkaiseril MVP & Adobe Community Professional

                There was a reason I asked for your scripts. If I am to provide you with code that you can cut and paste into your form, I need the details. Without the detail I can only provide code that you will have to edit before it will work with your form.


                I guess you want the day and month from the field you have created.  You did not tell me where that script is executed from. I would guess it is at the document level. Just as you filled in the date field you can also fill in the date and month fields and do it with the document level script and avoid a lot of repeated code in each of the fields. Make sure all of your fields are using a format of "None" since the script will be formatting the values.


                I only pull the date from the system once to make sure the same value is used for getting the day and month form the date.

                // get the system date object;

                var oDate = new Date();

                // fill in the "Date" field;

                this.getField("Date").value =  util.printd("mm/dd/yyyy", oDate);

                // fill in the day field;

                this.getField("Day").value =  util.printd("dd", oDate);

                // fill in the month field;

                this.getField("Day").value =  util.printd("mmm", oDate);

                • 5. Re: Date Formats
                  Karl Heinz Kremer Adobe Community Professional

                  The last line needs to be


                  this.getField("Month").value =  util.printd("mmm", oDate);
                  • 6. Re: Date Formats
                    Branchard0902 Level 1

                    Ok. I must be really thick today but I can't get anything to work today.


                    I put this code in the Date form field and got the result I wanted.

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

                    f.value = util.printd("mm/dd/yyyy", new Date());


                    Now I have another form field that is "Day".

                    I put this in and got the DD format.

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

                    f.value = util.printd("dd", new Date());


                    But this is not working for the MMM form field.

                    I tried using some of the other code from above but I can't seem to make it work.


                    What do I put in the "Date" script?

                    "Day" script?

                    "Month" script?

                    • 7. Re: Date Formats
                      Branchard0902 Level 1

                      Wait! I got it. I don't know what in the heck I did but I finally got it to work!!!!


                      WOO HOO