Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing a date within the past 50 years

I'm trying to pick a date past 50 year through jQuery datepicker but the select type of year shows only limited number of years. I've to repeatedly select year to go back to past years.

Here's jQuery script I'm using:

$(".datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    minDate: "-50Y",
    maxDate: "-6Y"
});

I'd created a fiddle http://jsfiddle.net/5xQb3/
Please check. I want to show all year in one time not selecting them repeatedly.
Also, I would like to display the date as yyyy-mm-dd format.

like image 686
Mohammad Faisal Avatar asked Dec 12 '25 18:12

Mohammad Faisal


2 Answers

you can use yearRange

$(".datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    changeMonth: true,
    changeYear: true,
    yearRange: "-50:-6"
});

Demo Fiddle

like image 185
Mohammad Masoudian Avatar answered Dec 15 '25 08:12

Mohammad Masoudian


add yearRange: "c-50:c-6" to your instantiation like so

$(".datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    minDate: "-50Y",
    maxDate: "-6Y",
    yearRange: "c-50:c-6"
});
like image 24
DGS Avatar answered Dec 15 '25 08:12

DGS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!