Copy link to clipboard
Copied
I need to do an Adobe form where the working days from one field to another must be counted. I've used the script below, but it is counting the days, and not only the workdays. Any suggestion as to what to amend to only count the workdays.
var strStart = this.getField("StartRow1").value;
var strEnd = this.getField("EndRow1").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 = days+1;
}
else
event.value = 0;
Assistance will be most appreciated.
Copy link to clipboard
Copied
What's your definition of "working days"? Does it exclude holidays?
Copy link to clipboard
Copied
Yes it excluded public holidays and weekends (Saturdays and Sundays)
Copy link to clipboard
Copied
Then you'll need to run a counter, starting from the first date and adding one each time, until you reach the last date. If the current date falls is a Saturday or a Sunday (which you can check using the getDay method), don't increment your counter. Also, if it falls on a holiday (you will need to define an array of holidays, including the year), then continue without incrementing the counter's value.
When you reach the end date your counter variable will hold the number of work days between the two.
I've developed a (paid-for) tool that does the opposite, ie. allow you to specify a starting date and a number of days and it calculates the end date (ignoring weekends and holidays, if you choose to). It can be easily adjusted to achieve what you described, though. You can find it here:
https://www.try67.com/tool/acrobat-apply-automatic-date-calculation