Home » Jquery » javascript – How to show the only the upcoming 3 months in date pickers

javascript – How to show the only the upcoming 3 months in date pickers

Posted by: admin February 24, 2020 Leave a comment

Questions:
<input id="datepicker" type="text">
$("#datepicker").datepicker({
  minDate: 0,
  beforeShowDay: function(d) {
    var day = d.getDate();
    return [day == 5 || day == 10 || day == 15 || day == 20 || day == 25];
  },
  beforeShow: function() {
    var dateTime = new Date();
    var hour = dateTime.getHours();
    var minute = dateTime.getMinutes();
    if (hour >= 18 && minute > 30) {
      $(this).datepicker("option", "minDate", "1");
    }
  }
});

How to show the only the upcoming 3 months from current i.e feb, march and april in date pickers and enable 5, 10, 15, 20, 25 dates in every and disable the date after 6:30 PM

How to&Answer:

you can disable all other date except upcoming three months.

$("#datepicker").datepicker({
  maxDate: '+3M', 
  numberOfMonths:3,
  minDate: 0,
  beforeShowDay: function(d) {
    var day = d.getDate();
    return [day == 5 || day == 10 || day == 15 || day == 20 || day == 25];
  },
  beforeShow: function() {
    var dateTime = new Date();
    var hour = dateTime.getHours();
    var minute = dateTime.getMinutes();
    if (hour >= 18 && minute > 30) {
      $(this).datepicker("option", "minDate", "1");
    }
  }
});