I have the following code which attaches the jQuery UI date picker widget to an input field:
console.log($("#profileDialog .date-picker").val());
$("#profileDialog .date-picker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
yearRange: "-115:-2",
defaultDate: $("#profileDialog .date-picker").val()
});
The console log outputs the value correctly (ex: 11/1/1955 12:00:00 AM), but when I click inside the input field, the date picker shows me a selected date of April 17 1897.
Any ideas why this might be happening?
The reason you see
1897as the year is because you’re setting thedateFormatasyy-mm-dd, when the default date is in the formatdd-mm-yy, which isn’t a valid date (in the given format).Here’s a fiddle