The code below is giving me trouble. When I select July 1st 11:00pm for fromDate, result 3 is being set to Thu Jun 02 2011 11:52:26. I check the values of fromDate and toDate in chrome and they seem fine but result 3 is getting set to a wacky date. Any solutions?
function(value, element, params) {
fromDate = new Date(startDate.val());
toDate = new Date(endDate.val());
result1 = this.optional(element);
result2 = fromDate <= toDate;
result3 = new Date();
result3.setDate(fromDate.getDate()+1);
result5 = (toDate.getDate()+0);
result4 = (fromDate.getDate()+1)>(toDate.getDate()+0);
return result1 || (result2 && result4);
}
result3.setDate(fromDate.getDate()+1)only sets the day of the month of your Date object. Sinceresult3creates a new Date object, this means thatresult3is not having its time set correctly.If you want to set
result3tofromDateplus one day, you’ll have to do something like this:However, since I’m not sure what your variables represent, it’s hard to diagnose.