I have the following jquery code that set up a default date on my search-by-date date pickers:
var fromDate = new Date();
var toDate = new Date();
fromDate.setDate(fromDate.getDate() - 6);
fromDate.setFullYear(fromDate.getFullYear() - 1);
$("#searchDateFrom").datepicker({ defaultDate: "-y -1m -6d" });
$("#searchDateFrom").val((fromDate.getMonth()) + '/' + (fromDate.getDate()) + '/' + (fromDate.getFullYear()));
$("#searchDateTo").datepicker();
$("#searchDateTo").val((toDate.getMonth()) + '/' + (toDate.getDate()) + '/' + (toDate.getFullYear()));
And the html:
<input type="text" id="searchDateFrom">
<input type="text" id="searchDateTo">
The issue is that sometimes I get invalid dates, for example today, I got the following dates:
9/25/2015-9/31/2016
I'm not sure how to make sure that the dates are valid ones.
Any help would be much appreciated.