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
$('#' + id).datepicker({
maxDate: "+30d",
minDate:0
});
Related videos on Youtube
Author by
Shruthi R
Updated on June 04, 2022Comments
-
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 over 10 yearsCan i disable the previous dates from this function??
-
Shruthi R over 10 yearsbootstrap datepicker will not accept maxDate, moreover previous dates are not disabling.
-
Shruthi R over 10 yearsbootstrap datepicker will not accept maxDate, moreover previous dates are not disabling.
-
Mr.G over 10 yearshe need bootstrap date-picker but in your fiddle have jquery date-picker.
-
Shankar S Bavan almost 3 yearsHow to exclude weekend from this 30 days?