Days calculation without counting holidays
Copy link to clipboard
Copied
Hi
I made a leave register form in acrobat pro XI.
In this file leave start & end entry are given in "fromdt" & "todt" text box respectively. I am using using popup calendar in those file. There is a text field "totaldays" where number of days leave availed is showing.
I used below code to calculate total days. I am using a reset button in this file.
// common document functions;
function GetField(cName) {
// get field object with error checking;
var oField = this.getField(cName);
if(oField == null) app.alert("Error accessing field named " + cName + "\nPlease check that this is the correct field name.", 1, 0);
return oField;
} // end GetField function;
function Scand(cFormat, cDateString) {
// using format convert date string to date object with error checking;
var oDate = util.scand(cFormat, cDateString);
if(oDate == null) app.alert("Error converting date " + cDateString + " with format of " + cFormat + "\nPlease check date string and date formatting.", 1, 0);
return oDate;
} // end Scand function;
// end common document functions;
//console.show();
//console.clear();
var strStart = this.getField("frdt1").value;
var strEnd = this.getField("todt1").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 = "";
// end custom calculation script
I want to calculate total days without counting holidays.
Any help would be appreciated.
Thanks
Copy link to clipboard
Copied
This is not such a simple task. You need to define a list of holidays (including the year, since some holidays change from year to year, like Easter), and then check if any of them fall between the start and end dates. If so, you need to count them and then add the same amount of days to your total. The same can be done with weekends.
I've created a script that allows you to do it very easily. You can find it here: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation
Copy link to clipboard
Copied
Hi
Thanks for the reply.
I am using below javascript code on mouseUp event of a text field to calculate working days without weekends (Thursday & Friday). I am using popup calendar in "StartDate" &"EndDate" fields.
If I keep date formatting of "StartDate" , "EndDate" text fields & popup calendar format as " DD/MM/YYYY", I am getting wrong result. It gives correct result in MM/DD/YYYY format.
Question-1: How can I apply DD/MM/YYYY format?
Question-2: How can I use this code in "TotalWorkingDays" field to calculate working days?
var dtStart = new Date(this.getField("StartDate").value);
var dtEnd = new Date(this.getField("EndDate").value)
var nDayStart = dtStart.getDay()
var nDayEnd = dtEnd.getDay()
var OneDay = 24 * 60 * 60 * 1000;
var TotalNumDays = (dtEnd.getTime() - dtStart.getTime())/OneDay;
// Fix up for Starting on Saturday or sunday
if(nDayStart == 4)
{
nDayStart = 6;
TotalNumDays -= 2;
}
else if(nDayStart == 5)
{
nDayStart = 6;
TotalNumDays -= 1;
}
// Fix up for ending on saturday or sunday
if(nDayEnd == 4)
{
nDayEnd = 3;// Make it friday
TotalNumDays -= 1;
}
else if(nDayEnd == 5)
{
nDayEnd = 3;// Make it friday
TotalNumDays -= 2;
}
var NumWeeks = Math.floor(TotalNumDays/7);
var extraDays = 1;
var DaysLeft = TotalNumDays - (NumWeeks*7);
if(DaysLeft)
{
var sepDays = nDayEnd - nDayStart;
if(sepDays > 0)
extraDays += sepDays;
else if(sepDays < 0)// Week end Split
extraDays += sepDays + 6;
}
var totalWorkingDays = NumWeeks * 5 + extraDays;
this.getField("TotalWorkingDays").value = 1+totalWorkingDays;
Any help would be great.
Regards

