Enable only current date till next 30 days - bootstrap datepicker

13,398

Solution 1

In Bootstrap datepicker Set Current date Use: startDate: new Date() it desible previous date.

Set next 30 days use: endDate: '+30d' It shows only 30 days from the current date

here the example code:

$('#datepicker').datepicker({ 
  startDate: new Date(), // controll start date like startDate: '-2m' m: means Month
  endDate: '+30d'

});

Solution 2

Try maxDate

$('#' + id).datepicker({ maxDate: "+30d" });

or

$('#' + id).datepicker( "option", "maxDate", "+30d" );


Updated after OP's comment

fiddle Demo

$('#' + id).datepicker({
    maxDate: "+30d",
    minDate:0
});

minDate

Share:
13,398

Related videos on Youtube

Shruthi R
Author by

Shruthi R

Updated on June 04, 2022

Comments

  • Shruthi R
    Shruthi R about 2 years

    In rails 3.2.13 project, I am using bootstrap datepicker plugin. Right now calender is displaying the current date by disabling the previous dates. Now I need to restrict the calender to select the current date + next 30 days only.

    I am using below code to disable the previous date,

    function currentDatePicker(id){
    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
    
     $('#' + id).datepicker({
        format: "yyyy-mm-dd",
        onRender: function(date) {
            return date.valueOf() < now.valueOf() ? 'disabled' : '';
        }
     });
    }
    
  • Shruthi R
    Shruthi R over 10 years
    Can i disable the previous dates from this function??
  • Shruthi R
    Shruthi R over 10 years
    bootstrap datepicker will not accept maxDate, moreover previous dates are not disabling.
  • Shruthi R
    Shruthi R over 10 years
    bootstrap datepicker will not accept maxDate, moreover previous dates are not disabling.
  • Mr.G
    Mr.G over 10 years
    he need bootstrap date-picker but in your fiddle have jquery date-picker.
  • Shankar S Bavan
    Shankar S Bavan almost 3 years
    How to exclude weekend from this 30 days?