I have 2 fields input and output dates. On certain conditions I set the endDate to be 1 year ahead of start date.
<input type='date' id='endDate'>
$("#startDate").change(function(){
var endDate = new Date($("#startDate").val());
endDate.setMonth(endDate.getMonth() + 1);
endDate.setFullYear(endDate.getFullYear() + 1);
var myDay = ("0" + endDate.getDate()).slice(-2);
var myMonth = ("0" + endDate.getMonth()).slice(-2);
$("#endDate").val(endDate.getFullYear() + '-' + myMonth + '-' + myDay);
}
The issue when I set the start date to 2-29-2016 I got the following error:
The specified value "2017-02-29" does not conform to the required format, "yyyy-MM-dd".
I expected the Date() function to take care of it. Apparently, they don't. Is this a bug?
Is their anyway faster than adding a bunch of if statements?