11 Replies Latest reply on Aug 17, 2017 12:11 AM by zizii22429128

    Time sheet

    zizii22429128

      Hello, greeting from Indonesia

      Im new for javascript, im trying make timesheet for daily planner. The first day is monday. I want to make  pdf automatically fill the first date for next monday. example: now is monday 8/14/2017, the date fill with this date, but if i make timesheet tomorrow, (tuesday 8/15/2017) the first date will show next monday date (8/21/2017). Could you help me. Thank you and im sorry my english is terrible. Thanks

        • 1. Re: Time sheet
          try67 MVP & Adobe Community Professional

          Your English is not terrible at all... It's actually very good. No need to apologize.

           

          So when do you want the dates to update? When you open a file? When you click on a button in the file?

          • 2. Re: Time sheet
            zizii22429128 Level 1

            try67

            Thank you for replying so fast....

            Actually i want the dates update when the file opened, so no need to fill the date manually, thank you so much

            • 3. Re: Time sheet
              zizii22429128 Level 1

              im sorrry, i make timesheet for pdf intearctive, thanks

              • 4. Re: Time sheet
                try67 MVP & Adobe Community Professional

                OK. Let's say the field is called "Monday". Go to Tools - JavaScript - Document JavaScripts, create a new item (let's call it "scripts"), and then paste this code into it (delete any pre-existing code that is generated there):

                 

                var d = new Date();
                while (d.getDay()!=1) d.setDate(d.getDate()+1);
                this.getField("Monday").value = util.printd("mm/dd/yyyy", d);
                
                • 5. Re: Time sheet
                  zizii22429128 Level 1

                  Oh God, finally, thanks...its working.

                  Could you help me again, im sorry i forgot, next day is tuesday, and i want to automatically fill it with the date, could you help me, im trying to google it and find this

                   

                  date(); // call my function

                  var d = util.scand("mm/dd/yy", event.value);   // retrieve the date from the Date1 field

                  var date2 = this.getField("Date2");                   // creates a variable for the Date2 field

                  var d2 = d.valueOf();                                        // converts d2 to a number that we can calculate with

                  d2 += 1000 * 60 * 60 * 24 * 7;  // adds 90 days (1000 miliseconds times 60 seconds times 60 minutes times 24 hours times 90 days

                  d3 = new Date(d2);                                          // create a new date based on the d2 variable

                  date2.value = util.printd("dd mmmm yyyy", d3);       // format and assign the new date variable to the Date2 field

                   

                  but it doesnt work and the error messages always appear

                  Thank you...you are my hero

                  • 6. Re: Time sheet
                    try67 MVP & Adobe Community Professional

                    You can use the same code as above, just change the field name and this part:

                    d.getDay()!=1

                    To:

                    d.getDay()!=2

                     

                    For Wednesday use 3, Thursday 4, etc.

                    • 7. Re: Time sheet
                      try67 MVP & Adobe Community Professional

                      By the way, if you're interested, I've developed a script that allows you to set up such date calculations easily and without having to write any code. You can find it here: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

                      • 8. Re: Time sheet
                        zizii22429128 Level 1

                        Ohhh.greattt..this is work, Thank you

                        I will inform my boss if he interested your usefull script, thank you

                        1 person found this helpful
                        • 9. Re: Time sheet
                          zizii22429128 Level 1

                          Hello, im sorry, i get a mistake, after i change the script to "d.getDay()!=2" for Tuesday, the date is 08/15/2017, what i mean is next day after first Monday after this day (08/22/2017)

                          Could you help me where is my mistake? thanks

                          • 10. Re: Time sheet
                            try67 MVP & Adobe Community Professional

                            Ah yes, I see the problem... In that case you can't use my code. You will need to add days to the original Monday date.

                            You can actually do it from the original script, like this:

                             

                            var d = new Date(); 
                            while (d.getDay()!=1) d.setDate(d.getDate()+1); 
                            this.getField("Monday").value = util.printd("mm/dd/yyyy", d);
                            d.setDate(d.getDate()+1);
                            this.getField("Tuesday").value = util.printd("mm/dd/yyyy", d);
                            d.setDate(d.getDate()+1);
                            this.getField("Wednesday").value = util.printd("mm/dd/yyyy", d);
                            // etc.
                            
                            • 11. Re: Time sheet
                              zizii22429128 Level 1

                              Greaattt...you really A maestro...its work..thanks