Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI Date Picker minDate and Date Range Seemingly Pretty Broken

When i set the minDate var to something below 2001, it just won't go below 2001 for the lower limit.

I've tried inserting the minDate value as a string, number, or Date object (as the documentation says you can use any of all 3 types)

Regardless of how i enter the value, it will not go below 2001.

Any Ideas?

like image 565
jfine Avatar asked Dec 12 '22 07:12

jfine


2 Answers

That is due to the fact that if you display the year with the option changeYear you must also set yearRange that otherwise default at +10:-10 For example:

$( "#datepicker" ).datepicker({ 
minDate: "-20Y",//go back 20 years
changeYear:true,//show a drop down to change year
maxDate: "+1M +10D", 
yearRange: 'c-100:c+10'//Show up to 100 years before and ten years after in the dropdown
});

fiddle here: http://jsfiddle.net/rUq7M/

like image 191
Nicola Peluchetti Avatar answered May 10 '23 07:05

Nicola Peluchetti


You may want to like this: The values given here are just for illustration purpose, you need to use values based on your requirements.

$(function () {
            $("#datepicker").datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: "yy-mm-dd",
                yearRange: '1934:2004',
                defaultDate: '1980-01-01'
            });
        });
like image 23
pramodtech Avatar answered May 10 '23 06:05

pramodtech