Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Datepicker default year always 2013

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.

like image 829
user2330621 Avatar asked Sep 16 '25 22:09

user2330621


2 Answers

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'

        });
    });

JSFiddle

like image 91
Praveen Avatar answered Sep 19 '25 13:09

Praveen


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"

        });
    });
like image 36
Mody Avatar answered Sep 19 '25 14:09

Mody