You can use the following script to compute the difference in days. You may need to adjust the date string format and field names to match your form.
// start document level functions;
function GetField(oDoc, cField){
var oField = oDoc.getField(cField); // get field object for named field in specified PDF doc;
if(oField == null){
// trap and report error;
app.alert("Field " + cField + " not found.\nCheck for existance of field.", 1, 0, "Field Access Error");
}
return oField; // return field object;
}
function Scand(cFormat, cDateTime){
var oDate = util.scand(cFormat, cDateTime); // convert date string to date object using format;
if(oDate == null){
// trap and report conversion error;
app.alert("Error converting " + cDateTime + " using format " + cFormat, 1, 0, "Date/Time Conversion Error");
}
return oDate;
}
function Date2Days(cFormat, cDateTime){
var nDays = null;
var oDate = Scand(cFormat, cDateTime); // convert to date object;
if(oDate != null){
oDate.setHours(0, 0, 0, 0); // set to midnight;
nDays = Math.floor((oDate.getTime() / (1000 * 60 * 60 * 24))); // convert to whole days;
}
return nDays;
}
// end document level functions;
var nDiffDays = "";
var cDateFormat = "d-mmm-yyyy"; // change as needed to match date field format;
var oStart = GetField(this, "StartDate"); // field for start date;
var oEnd = GetField(this, "endDate"); // field for end date;
if(oStart != null && oStart.value != "" && oEnd != null && oEnd.value != ""){
// compute difference in days;
nDiffDays = Date2Days(cDateFormat, oEnd.value) - Date2Days(cDateFormat, oStart.value);
}
event.value = nDiffDays; // set field value;
The functions are used to minimize the amount of repeated code. The functions also include error reporting and trapping to help you in your debugging if needed. FormCalc includes some similar functions as built-in functions, but with Acrobat JavaScript one has to provide the code to do the job of the built-in functions.