These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Excluding weekends in Calculation of days between dates

jpmeyer8116
Registered: Sep 29 2009
Posts: 12

I have the following javascript to calculate the # of days between two dates and it works like a charm. However I need to exclude weekends in the calculation. Any thoughts? I looked through other posts and found one similiar request but I could not make sense of it. I also need the answer to be 1 if the start date and end date are the same. Any suggestions?

var strStart = this.getField("txtRevStart").value;
var strStop = this.getField("txtRevStop").value;
if(strStart != "" & strStop != "")
{
var dateStart = util.scand("mm/dd/yyyy",strStart);
var dateStop = util.scand("mm/dd/yyyy",strStop);
var diff = dateStop.getTime() - dateStart.getTime();
// One Day = (24 hours) x (60 minutes/hour) x
// (60 seconds/minute) x (1000 milliseconds/second)
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
event.value = days;
}
else{
event.value= ""}

My Product Information:
Acrobat Standard 9.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
For each Date object you can use the getDay method and determine which day of the week it is. So you can do this on your start and stop dates, and deduce from that how many weekends have been in the middle.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

jpmeyer8116
Registered: Sep 29 2009
Posts: 12
I have done some research on the getDay method but still do not understand how this fits in my scripting. Any examples would be appreciated.