Disable some hours bootstrap datetimepicker

maures picture maures · May 5, 2015 · Viewed 10.3k times · Source

I want to disable selecting some hours with bootstrap datetimepicker because I want to select only time from 8:00 am to 19:00 pm.

I can't find nothing about that. Can you help me?

Answer

Konservin picture Konservin · Jul 2, 2015

This should work:

$(".datepicker").datetimepicker({
    hoursDisabled: '0,1,2,3,4,5,6,7,18,19,20,21,22,23'
});

and also this:

    hoursDisabled: [0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23]

Because in bootstrap-datetimepicker.js:

    setHoursDisabled: function (hoursDisabled) {
        this.hoursDisabled = hoursDisabled || [];
        if (!$.isArray(this.hoursDisabled)) {
            this.hoursDisabled = this.hoursDisabled.split(/,\s*/);
        }
        ...
    },