I would like to disable different months in each of the date picker years, in particular, at the beginning and at the end of the year. I know that I can use the beforeShowDay method to run some code that can return true and false to enable / disable dates. Now I want to turn off the months in September - December 2005 and in November + December in 2009, but I'm not quite sure how to do this.
When I date.getYear() out of date.getYear() , I get numbers like 104 105, when I expect to get 2014 and 2015, etc., so I'm not sure how I can check the year, then switch and set the values ββto true / false based on the minimum and maximum arrays that I created that will contain the months that I want to exclude.
Js
var minYear = 2005, maxYear = 2009, excludeMinYearMonths = [8, 9, 10, 11], excludeMaxYearMonths = [10, 11]; $("#datepicker").datepicker({ changeMonth: true, changeYear: true, yearRange: minYear + ':' + maxYear, beforeShowDay: function (date) { console.log(date.getYear()); if (date.getYear() === minYear) { if ($.inArray(date.getMonth(), excludeMinYearMonths) > -1) { return [false, '']; } return [true, '']; } if (date.getYear() === maxYear) { if ($.inArray(date.getMonth(), excludeMaxYearMonths) > -1) { return [false, '']; } return [true, '']; } }, defaultDate: '01/01/05' });
Jsfiddle: http://jsfiddle.net/qA9NT/18/
source share