Counting only working days in Adobe Forms

New Here ,
Jul 08, 2022 Jul 08, 2022

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.

 

 

 

 

TOPICS
PDF forms

Views

42

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

What's your definition of "working days"? Does it exclude holidays?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

Yes it excluded public  holidays and weekends (Saturdays and Sundays)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

LATEST

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines