-1

I have implemented a bootstrap datepicker for policy start, so that I want to show user to select dates from current month and next month only.

Can anyone tell me how is it possible in bootstrap datepicker?

$(".policy-start-dp").datepicker({

});
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
Muhammad Owais
  • 980
  • 3
  • 17
  • 37
  • Possible duplicate of [How to restrict the selectable date ranges in Bootstrap Datepicker?](https://stackoverflow.com/questions/11933173/how-to-restrict-the-selectable-date-ranges-in-bootstrap-datepicker) – VincenzoC Mar 11 '18 at 23:21

2 Answers2

2

You need to set the minimum and maximum values of the date picker

    //Get Current Date
    var date = new Date();

    //Create Variable for first day of current month
    var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);

    //Create variable for last day of next month
    var lastDay = new Date(date.getFullYear(), date.getMonth() + 2, 0);


    $( "#datepicker" ).datepicker({ 
        minDate: firstDay, 
        maxDate: lastDay 
    });

Hope that helps :)

1

no need to set start and end date just pust the "startDate" code is below.

var changeDateFormat = () => {
if ($(fileMonths).parent().parent().hasClass('sandbox-container')) {
    $('#fileMonths').datepicker({
        autoclose: true,
        minViewMode: 1,
        startDate: '0m',
        format: "mm/yyyy"
    });
}

};

date picker months

enter image description here

Ravi Mariya
  • 1,210
  • 15
  • 19