I have a datepicker that is supposed to go from 1803 to 1995, but if you pick a day and month without choosing the year, it defaults to 2013, even though it would display 1803. How could I fix this?
Here is my code
$(function() {
$( "#date" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1803:1995",
dateFormat: "yy-mm-dd",
});
});
I have tried using default date, but then that stops me from changing the year.
Yes, by default it is using the current date. To change this use either options defaultDate
or setDate
$(function() {
$( "#date" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1803:1995",
dateFormat: "yy-mm-dd",
defaultDate: '1803-01-01'
});
});
You can use the defaultDate property, your code becomes like this
$(function() {
$( "#date" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1803:1995",
dateFormat: "yy-mm-dd",
defaultDate: "1803-01-01"
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With