Avatar

Level 7

You need to use the 'if' statement to see if a date has been entered for both dates and then perform the calculation or clear the field.

var oneDay = 24*60*60*1000;

if(rentalbegin.rawValue != "" & rentalend.rawValue != "") {

var firstDate = new Date(rentalbegin.rawValue);

var secondDate = new Date(rentalend.rawValue);

Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));

} else {

"";

}

You might find FormCalc an easier language to perform this calculation as the 'Date2Num' function returns the number of days since the Epoch date and not the number of milliseconds and has the "HasValue()" function.