7 Replies Latest reply on Feb 4, 2011 11:23 AM by gkaiseril

    Java Script help

    burlingtonnow

      I am trying to calculate days within dates. My pdf will open with the current date showing. I want the user to input another date in a cell  and the calculation I want is the imputed date plus the current date to equal a whole number.  2/3/2011+2/7/2011 = 4. Is there a java script that will give a whole number?

        • 1. Re: Java Script help
          gkaiseril MVP & Adobe Community Professional

          You have to convert your text string dates to the number of milliseconds since the Epoch date for JavaScript. You can use the 'util.scand' method to convert the strings to the JS date object. Now you can use any of many methods to extract the number of milliseconds from the date time object. Once you get that number, you only need to use sutraction, multiplication, divison, and some rounding to get the the number of days.

           

          Math.floor( (util.scand("m/d/yyyy", "2/7/2011") -  util.scand("m/d/yyyy","2/3/2011")  ) / (1000 * 60 * 60 * 24) )

          • 2. Re: Java Script help
            burlingtonnow Level 1

            Thank you for your answer but How do I apply this script.

             

             

             

            Math.floor( (util.scand("m/d/yyyy", "2/7/2011") -  util.scand("m/d/yyyy","2/3/2011")  ) / (1000 * 60 * 60 * 24) )

            • 3. Re: Java Script help
              burlingtonnow Level 1

              Also can you answer this question.

              Will a pdf that I have created use an auto date. Which is to say every day that I open this pdf will it have the correct date on it? I have to be able to use the correct date in the calculation in order to get the days count.

               

              Again Thank you for your help

              • 4. Re: Java Script help
                gkaiseril MVP & Adobe Community Professional

                That depends upon when and where you want it to happen.

                 

                You can add it to a field calculation.

                 

                You can make a button that pops up an alert with the result.

                 

                You can make a link that fill s form field.

                 

                and on and on.

                 

                You can use "new Date();" to get the current date an time.

                • 6. Re: Java Script help
                  burlingtonnow Level 1

                  To GKaiseril with respect to the JS you said Math.floor( (util.scand("m/d/yyyy", "2/7/2011") -  util.scand("m/d/yyyy","2/3/2011")  ) / (1000 * 60 * 60 * 24) )

                   

                  1, can I use this script in Acrobat Pro 9

                  2. If so In the text field Properties what tab do I add the script above...ie Action, Format, Validate , or Calculate

                  3. with resect to the Date is there more script than what you gave me and again where do I apply it in the Text Field Properties tabs?

                   

                  Again thank you for your help

                  • 7. Re: Java Script help
                    gkaiseril MVP & Adobe Community Professional

                    It appears you want or need a general or algebra like answer, but you asked a very very specific question. You need to replace your required date strings with a variable for the start and end date, along with the appropriate general format of the date strings. You also will need to provide a method to store or display the results. Where you use the code depends upon exactly what you are attempting to accomplish. If you need to make sure the date is not more than 4 days into the future, then you might use the code within the validation action. But if you want to display the difference in days between 2 dates then it could be used in the calculation action.

                     

                    Working with date and time in Acrobat JavaScript (Part 1 of 3) by Thom Parker

                    Working with date and time in Acrobat JavaScript (part 2 of 3) by Thom Parker