2 Replies Latest reply on Apr 29, 2016 12:13 PM by gkaiseril

    Add working days to field

    tonymaus

      Hello

       

      i"m new to acrobat java-script

       

      How do i add 370 working days to a date field dd/mm/yyyy

       

      Thanks

        • 1. Re: Add working days to field
          try67 MVP & Adobe Community Professional

          This is tricky. You would need to study the Date object and the methods associated with it. You would also need to clearly define what you mean by "working days". Does it include holidays? If not, you'll need to write a list of holidays and ignore them alongside the weekends when adding the dates to the original value.

           

          If you're interested, I've developed a tool that allows you to set up such a calculation easily (including the option to ignore weekends and even holidays). You can purchase it from here: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

          • 2. Re: Add working days to field
            gkaiseril MVP & Adobe Community Professional

            Have you searched for add days?

             

            This will require custom JavaScripting for the calculation, so  you will need to do some coding.

             

            Also what do you mean by "working days"?

             

            If we need to figure out the number of working days we need to know more about the starting date and holidays.

             

            A custom JavaScript  to add a specific number of days to a field using a starting date in another field:

             

            var cStartDateField = "StartDate"; // start date field name;
            var cDateFormat = "mm/dd/yyyy"; // format for date display;
            var nAddDays = 370; // number of days to add;
            event.value = ""; // clear the reuslt field;
            var oStartDate = this.getField(cStartDateField); // get field object for starting date;
            if(oStartDate == null)  app.alert("Error accessing field " + cStartDateField, 1, 0);
            var cStartDate = oStartDate.valueAsString; // get start date field value;
            if(cStartDate != "") {
            // only compute if we have data;
            var oEndDate = util.scand(cDateFormat, cStartDate); // convert to JavaScript date object;
            if(oEndDate == null) app.alert("Error converting " + cStartDate + " to date object", 1, 0);
            oEndDate.setDate(oEndDate.getDate() + nAddDays); // add number of days to start date object;
            event.value = util.printd(cDateFormat, oEndDate); // format result as needed;
            } // end add days;

             

            There are other possible ways to do this, but this maybe the easiest to follow.