1

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.

user3378165
  • 6,546
  • 17
  • 62
  • 101
  • Maybe this will help you http://stackoverflow.com/questions/8054009/jquery-javascript-is-it-a-date-validate-whether-is-a-date – ArmKh Oct 31 '16 at 08:23

0 Answers0