1 Reply Latest reply on May 10, 2017 4:42 AM by try67

    Calculate business days between two dates

    Diego1966

      Good evening, I would need a big help, in a PDF form I need to visualize in a field that we call "TotDayi" a number obtained from the interval of two date fields, which we call "DateStart" and "DateEnd", as title The days are workable and can be developed in a working week of 5 days or 6 days (Saturday included), all this to calculate the days of actual work are also considered festivities including the patron saint and easter (or rather The pasquetta as the easter always falls on Sunday), in order to return the actual days between two dates I used this script:

       

      Code:

      //console.show();
      //console.clear();


      var strStart = this.getField("dalgg").value;
      var strEnd = this.getField("Algg").value;
      if(strStart.length && strEnd.length)
      {
       
      var dateStart = util.scand("dd/mm/yyyy",strStart);
       
      var dateEnd = util.scand("dd/mm/yyyy",strEnd);
       
      var diff = dateEnd.getTime() - dateStart.getTime();
       
      var oneDay = 24 * 60 * 60 * 1000;
       
      var days = Math.floor(diff/oneDay);
       
      event.value = 1+days;
      }
      else
       
      event.value = 0;

       

       

      Where 1 + days returns 1 if the working day is between the same date (start date today, end date today), vice versa if I did not add that 1 returned me 0.

       

      Could you give me a helping hand please? I do not know how to do it, I am very scarce, how can I implement this code to determine the sabbaticals on Sundays easter and eclectic festivals so that they are taken away by the number of days that would actually work and could choose whether the calculation of days ago Done on 5 working days or on 6 if we include Saturday?

       

       

      Thanks to everyone in any case