JQuery DatePicker Min Max dates

I have setup and work on setting jQuery date, but I would like to help with setting minDate and maxDate parameters. My current code is below (without these options). How to set minDate 3 months before defaultDate and maxDate as 28 days after defaultDate?

var expdisp = $("#expdisp").attr("value"); $("#expirydate" ).datepicker({ showOn: "button", buttonImage: "images/calendar.gif", buttonImageOnly: true, dateFormat: "dd/mm/yy", defaultDate: expdisp, showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true, }); 
+6
source share
4 answers
 $(function() { $( "#datepicker" ).datepicker({ changeYear: true, minDate: '-3M', maxDate: '+28D', }); }); 

JSFiddle Demo

UPDATE

You can calculate the maximum and minimum tour dates with a default date, and then assign it to select a date.

 var expdisp = $("#expdisp").attr("value"); $("#expirydate" ).datepicker({ showOn: "button", buttonImage: "images/calendar.gif", buttonImageOnly: true, dateFormat: "dd/mm/yy", defaultDate: expdisp, showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true, minDate: '-3M', maxDate: '+28D', }); 

Update demo

+12
source

maxDate : - Sets the maximum date that can be selected. Accepts a date object or relative number. For example: +7 or a line, for example + 6 m.

minDate: - Sets the minimum date that can be selected. Accepts a number, date object, or string.

 $(document).ready(function() { $("#date").datepicker({ minDate: -3, maxDate: "1w" }); 

});

Refer: - set the minimum and maximum date for jquery datepicker

+2
source

You can try:

 var expdisp = $("#expdisp").attr("value"); $("#expirydate" ).datepicker({ showOn: "button", buttonImage: "images/calendar.gif", buttonImageOnly: true, dateFormat: "dd/mm/yy", defaultDate: expdisp, showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true, minDate: -3M, maxDate: +28D }); 
0
source

You can also use specific date ranges. I added a minimum start date with max. + 14D. You just need to remember to stay in line with your date format and use "/" instead of "-" between MM / DD / YYYY.

 $('#Date').datepicker({ changeMonth: true, minDate: '10/19/2016', maxDate: '+14D', }); 
0
source

All Articles