I have tried to manipulate the numerous information I've found on this topic but can't seem to understand how to get this to work. I'm not much of a programmer and my knowledge of it stops with excel...
I am trying to create a leave request form for our office. I've used the wizard and use the base personal leave template in Adobe Lifecycle Designer and modified as needed.
There are three fields I wish to manipulate StardDate[0] , EndDate[0] & Days[0].
Start Date and End Date are "Date/Time Fields" formatted as such "date{DD-MMM-YY}"
When a user enters in the Start Date and End date using the calendar selections I want the form to automatically calculate the number of working days between these two dates and enter it in the Days[0] Numeric Field.
I tried this http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=3164 This example uses a "calculate" button where is I just want it to do it automatically if possible?
But I still end up with a blank field in Days[0]. I can't seem to understand how to correctly use Date2Num to have it report anything other than 0 nor do I have a clue where to start with Javascript...
Any assistance would be greatly appreciated.
This is the code I've tried so far:
//var dtStart = new Date(StartDate[0]) //var dtEnd = new Date(EndDate[0]) var dtStart = new Date(this.getField.StartDate[0].value); var dtEnd = new Date(this.getField.EndDate[0].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 == 6) { nDayStart = 1; TotalNumDays -= 2; } else if(nDayStart == 0) { nDayStart = 1; TotalNumDays -= 1; } // Fix up for ending on saturday or sunday if(nDayEnd == 6) { nDayEnd = 5;// Make it friday TotalNumDays -= 1; } else if(nDayEnd == 0) { nDayEnd = 5;// Make it friday TotalNumDays -= 2; } var NumWeeks = Math.floor(TotalNumDays/7); // Extra is set to 1 to include the end day in the calculation var extraDays = 1; var DaysLeft = TotalNumDays - NumWeeks * 7; if(DaysLeft) { // Look for weekend split 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 = totalWorkingDays;
Thanks. Chris.
George Kaiser