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

Business / Working Days calculations in LCD

R_Boyd
Registered: Nov 1 2007
Posts: 151

I've had a look at this forum for a solution but have not found a satisfactory way to calculate the number of business days between two dates. I need to do this for an annual leave form.

The solution posted by thomp was an AcroForm but when I open it in LCD 8.2 the scripting does not work. The link to his article on date and time formats is broken presumably following the recent changes to the AUC website.

Searching online has uncovered a number of possible scripts that could help but they are primarily written in the context of an HTML page. A search in the help pages and Scripting Reference section in LCD seems to indicate that a key element of the script (getDay)will not work as it is not supported in LCD.

function calcBusinessDays(dDate1, dDate2) {         // input given as Date objects
 
  var iWeeks, iDateDiff, iAdjust = 0;
 
  if (dDate2 < dDate1) return -1;                 // error code if dates transposed
 
  var iWeekday1 = dDate1.getDay();                // day of week
  var iWeekday2 = dDate2.getDay();
 
  iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1;   // change Sunday from 0 to 7
  iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;
 
  if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1;  // adjustment if both days on weekend
 
  iOriginalWeekday1 = iWeekday1;    // only count weekdays
  iOriginalWeekday2 = iWeekday2
 
  // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
  iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000)
 
  if (iOriginalWeekday1 <= iOriginalWeekday2 {
    iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1)
  } else {
    iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2)
  }
 
  iDateDiff -= iAdjust                            // take into account both days on weekend
 
  return (iDateDiff + 1);                         // add 1 because dates are inclusive
 
}

Is there an alternative scripting solution I can use to get around this?

My Product Information:
LiveCycle Designer, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi R_Boyd,

Here are the working links for Thom Parker's 3 part series on working with Time and Dates-
http://www.acrobatusers.com/tutorials/2006/date_time_part1
http://www.acrobatusers.com/tutorials/2006/date_time_part2
http://www.acrobatusers.com/tutorials/working-date-and-time-acrobat-javascript-part-3-3

You absolutely can calculate the difference between dates in LiveCycle Designer PDF forms- even excluding weekends. I don't think I've seen any exact code solutions for this posted here in the forums (do an thorough search to be sure), but with those tutorials, the LCD scripting Reference, and a Core JS Reference you have everything you need to develop the solution.


Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com