Question

I am using jquery datepicker, I have to show in this format mm/yy, I have implemented it accordingly,but the calendar is displaying the starting year 2004, I want it to display from 1980, how can I do that Fiddler Code This is my datepicker code

 $("#txtbox").datepicker({
                prevText: "",
                nextText: "",
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                dateFormat: 'mm/yy',
                onClose: function (dateText, inst) {
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            });

<input type="textbox" id="txtbox">
Was it helpful?

Solution

Set the yearRange option. Add yearRange: "1980:2014", (or whatever start and end years you need):

 $("#txtbox").datepicker({
     prevText: "",
     nextText: "",
     changeMonth: true,
     changeYear: true,
     showButtonPanel: true,
     dateFormat: 'mm/yy',
     yearRange: "1980:2014",
     onClose: function (dateText, inst) {
         var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
         var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
         $(this).datepicker('setDate', new Date(year, month, 1));
     }
 });

jsFiddle example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top