I have a Jquery UI datepicker like this.
I can only select month and year from the datepicker.
code:
$('#datepicker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'M yy',
maxDate: '0',
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function(input, inst) {
$(inst.dpDiv).addClass('calendar-off');
}
});
If I set maxDate: '0'
the maximum month and year I can select is the current month and current year.
I want to set the maximum month and year using jquery.
For a normal datepicker with date,month,year, first I remove this maxDate: '0'
code and I used the following code to set the maximum date
var maximumDate = '07-15-2013';
$("#datepicker" ).datepicker( "option", "maxDate", maximumDate);
How can i set the maximum date in month and year picker? The above code is not working in this case.Please give me your suggestions.
Tried the following code.It works fine for me.
var date = new Date("2013-07-15");
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$("#datepicker" ).datepicker( "option", "maxDate", new Date(currentYear, currentMonth, currentDate));
Example fiddle I created:FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With