Reputation:
Script
$(function () {
$('#datetimepicker6').datetimepicker();
$('#datetimepicker7').datetimepicker({
useCurrent: false //Important! See issue #1075
});
$("#datetimepicker6").on("dp.change", function (e) {
$('#datetimepicker7').data("DateTimePicker").minDate(e.date);
});
$("#datetimepicker7").on("dp.change", function (e) {
$('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
});
});
I'm using bootstrap datetimepicker. How do I disable weekends, public holidays and all past days before today with datetimepicker? I can't seem to find any documentation or solutions and I have no idea how to do it as well. My public holidays are in an array.
Upvotes: 1
Views: 1045
Reputation: 3489
This may help you.
HTML
<br/>
<div class="row">
<div class="col-md-12">
<h6>Datetimepicker</h6>
<div class="form-group">
<div class="input-group date" id="datetimepicker">
<input type="text" class="form-control" /> <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
</div>
</div>
</div>
JavaScript
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datetimepicker').datetimepicker({ minDate: new Date(currentYear, currentMonth, currentDate),daysOfWeekDisabled: [0, 6],
disabledDates: [
moment("12/25/2015"),
moment("12/24/2015")
]});
});
Include the public holidays in moment
as shown.
Fiddle here
Upvotes: 1