5 Replies Latest reply on Feb 4, 2017 4:11 PM by Joel_Geraci

    Add 36 hours to date and time and adobe form

    tngk67853927

      Hi, I am trying to create a Adobe Form which automatically add 36 hours to the previous date and time entered in the dd/mm/yy HH:MM format. I was wondering if there is any advice on how to do that on Adobe acrobat DC?

        • 1. Re: Add 36 hours to date and time and adobe form
          Joel_Geraci Adobe Community Professional

          I created a JavaScript Date Library for Acrobat to make just such calculations much easier. It's free and has an installer.

           

          The code would be...

           

          previousDate.changeBy({"hours": 36});

           

          Negative number reverse time.

           

          The practicalPDF Date Library for Adobe Acrobat

          1 person found this helpful
          • 2. Re: Add 36 hours to date and time and adobe form
            tngk67853927 Level 1

            Hi Joel,

             

            Thank you for your advice and suggested site. I have tried following the steps in your post and site but could not manage to do it. I am really sorry. I am still pretty new with regards to JavaScript.

             

            I plan to create a form (as attached) where if I enter the date in 'Date1' in the format of dd/mm/yy HH:MM and the interval in 'Interval1' of 24, 36 or 48 hourly, i could create a pdf form where it could automatically add it together on 'Date2'. I tried using the suggested codebut it didn't work.

             

            Any help would be very much appreciated. Thank you again for your help.

             

             

            chart 2.png

            • 3. Re: Add 36 hours to date and time and adobe form
              Karl Heinz Kremer Adobe Community Professional

              This is a good example for why it's a bad idea to try to copy&paste your way to a JavaScript solution without a good background in how JavaScript works:

               

              Joel's code assumed that you already had a variable (of type Date) named "previousDate". If that's the case, then this one line would add 36 hours. This would not get the previous date, and it would not set your current field to the result of that operation. You need to add more code around that one statement to come up with a solution that works for you. We cannot teach you JavaScript, that is something that you need to learn on your own. Take a look here for some guidance about how to get started: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

               

              You need to be able to take something like Joel's answer and then build your own script around that. And for that, you need a good understanding of JavaScript.

               

              Did you add Joel's library to your form? The solution he presented will not work without that library.

               

              The following code should work by getting the date from a field named "Date1", and then calculating the value for another field:

               

              // get the date from the field "Date1"
              var dateString = this.getField("Date1").value;
              if (dateString != "") {
                  var previousDate = util.scand("m/d/yyyy h:MM tt", dateString);
                  previousDate.changeBy({"hours": 36});
                  event.value = util.printd("m/d/yyyy h:MM tt", previousDate);
              }
              else {
                  event.value = "";
              }
              

               

              You need to adjust this to fit your specific form and field formats. If you have a problem with what certain JavaScript methods do, (e.g. util.scand() or util.printd()), look them up in the Acrobat JavaScript API documentation: Acrobat DC SDK Documentation

              • 4. Re: Add 36 hours to date and time and adobe form
                tngk67853927 Level 1

                Hi Karl,

                 

                thank you for your explanation and help.

                • 5. Re: Add 36 hours to date and time and adobe form
                  Joel_Geraci Adobe Community Professional

                  Yes Karl, thanks for the further explanation. I was swamped on Friday and didn't see that more help was needed.