I am showing only year in calender view using datepicker.
But I want to set maximum year range to current year and minimum year range to 1900 and disable year before/after range I want to set in Datepicker like the below image.
Here is my javascript code:
$("#datepicker").datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years",
autoclose: true,
changeYear: true,
yearRange: '1900:' + new Date().getFullYear()
});
But year range is not working for me. Any help will be highly appreciated.
Thanks!
edit - different approach
try using the minDate and maxDate attributes:
let cur_year = (new Date).getFullYear();
$( "#datepicker" ).datepicker({
minDate: new Date(1900, 0, 1),
maxDate: new Date(cur_year, 11, 31)
});
you should convert the date back to string after you get the current year, currently, you are trying to add a date to a string (that's not possible)
so it should look something like that:
$("#datepicker").datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years",
autoclose: true,
changeYear: true,
yearRange: '1900:' + new Date().getFullYear().toString()
});