user4403536
user4403536

Reputation:

Bootstrap DatetimePicker disable specific dates of week ( sunday - Wednesday)

Im using Bootstrap DateTimePicker to show a calender, and i want to remove some days from the calender (disable them)

$(function () {
        $('#datetimepicker1').datetimepicker({
            inline: true,
            format: "dd MM yyyy",
            defaultDate: null,
            disabledDates: function (date) {
                var day = date.getDay();
                return [(day != 1 && day != 2)];
            }
        })
    }).on('dp.change', function (e, selectedDate, $td) {
        //var time = e.date.format("HH:mm:ss");
        //alert(e.date + '  -  ' + time);
        $('.input-field1').val(e.date.format("DD/MM/YYYY"));
        if (check) {
            $('.FormDownDateSelect').slideToggle("fast", function () { });
        }
    });

I tried the code above Special the part with DisabledDates but it dont work. Can someone tell me how to disable some days of the week. Sunday to Wednesday.

Plugin

Upvotes: 2

Views: 10428

Answers (2)

Marian Polacek
Marian Polacek

Reputation: 2925

You could use daysOfWeekDisabled setting described here.

Your code would look somehow like this:

$(function () {
    $('#datetimepicker1').datetimepicker({
        inline: true,
        format: "dd MM yyyy",
        defaultDate: null,
        daysOfWeekDisabled: [0, 6]
    })
}).on('dp.change', function (e, selectedDate, $td) {
    //var time = e.date.format("HH:mm:ss");
    //alert(e.date + '  -  ' + time);
    $('.input-field1').val(e.date.format("DD/MM/YYYY"));
    if (check) {
        $('.FormDownDateSelect').slideToggle("fast", function () { });
    }
});

Upvotes: 5

teo van kot
teo van kot

Reputation: 12491

I belive it will be easier to use beforeShowDay instead of disabledDates function like this:

beforeShowDay: function(date){
    var day = date.getDay();
    if(day != 1 && day != 2){
        return {
            enabled : false
        };
    }
    return;
}

Upvotes: 0

Related Questions