I have two Datepickers and based on the date selection of first datepicker, the second datepicker should show allow user to choose a date within 1 year of the date selected in the first datepicker. The code I am using is working perfectly for Chrome but it is giving different result in IE11. When I use the alert method to view the date, in Chrome I get the result "Wed Oct 10 2018 00:00:00 GMT+0530 (India Standard Time)" whereas in IE the result is "Wed Oct 10 1918 00:00:00 GMT+0530 (India Standard Time)"
$('.datepicker1').datepicker({
dateFormat: "mm/dd/y",
changeMonth: true,
changeYear: true,
yearRange: "-10:+10",
showOn: "both",
buttonText: "<i class='fa fa-calendar'></i>",
onSelect: function (date) {
var selectedDate = new Date(date);
alert(selectedDate)
var date = new Date(Date.parse(selectedDate));
date.setFullYear(date.getFullYear() + 1);
var newDate = date.toDateString();
newDate = new Date(Date.parse(newDate));
$(".datepicker2").datepicker("option", "maxDate", newDate);
}
});
$('.datepicker2').datepicker({
dateFormat: "mm/dd/y",
changeMonth: true,
changeYear: true,
showOn: "both",
buttonText: "<i class='fa fa-calendar'></i>"
});
Below is the Razor syntax used
@Html.EditorFor(m => m.date1, new { htmlAttributes = new { @class = "datepicker1 form-control", placeholder = "00/00/00", @readonly = "readonly" } })
@Html.EditorFor(m => m.date2, new { htmlAttributes = new { @class = "datepicker2 form-control", placeholder = "00/00/00", @readonly = "readonly" } })
Can anyone help me figure out where I went wrong? Seems like Date.Parse might not be working as expected in IE, do we have a workaround? Thanks in advance