Bootstrap datepicker configuration to block specific dates (holidays)
14,122
Solution 1
//a array of dates that should be blocked
var forbidden=['12/25/2014','12/24/2014']
$('#datepicker').datepicker({
beforeShowDay:function(Date){
//
var curr_day = Date.getDate();
var curr_month = Date.getMonth()+1;
var curr_year = Date.getFullYear();
var curr_date=curr_month+'/'+curr_day+'/'+curr_year;
if (forbidden.indexOf(curr_date)>-1) return false;
}
})
OR:
http://jsfiddle.net/zsqvjvkd/1/
var forbidden=['2014-12-25','2014-12-24']
$('#datepicker').datepicker({
beforeShowDay:function(Date){
var curr_date = Date.toJSON().substring(0,10);
if (forbidden.indexOf(curr_date)>-1) return false;
}
})
Solution 2
With version 1.3.1+ you can simply use datesDisabled
option: http://bootstrap-datepicker.readthedocs.org/en/latest/options.html#datesdisabled
Author by
Scott C Wilson
Focused on ecommerce. Most of my work is on Zen Cart, but I also work on other shopping carts like: OpenCart osCommerce BigCommerce Shopify I think StackOverflow is a great resource, and I'm #SOreadytohelp.
Updated on June 04, 2022Comments
-
Scott C Wilson almost 2 years
Has anyone figured out how to configure datepicker to not display specific dates (such as, say, July 4th)? It would seem that this could be done using the beforeShowDay but I'm not positive.
-
Scott C Wilson over 9 yearsJust before the beforeShowDay function I also added
daysOfWeekDisabled: "0",
in order to block sundays as well. -
Davi Lima almost 9 yearsWith version 1.3.1+ you can simply use
datesDisabled
option: bootstrap-datepicker.readthedocs.org/en/latest/… -
Davi Lima over 8 yearsAlso see: stackoverflow.com/questions/10234153/…
-
Anupal over 8 yearsQuick question and how: Can we only change the background color to some for only warning to user while picking dates ?