I am trying to disable specific times for specific dates using the jQuery DateTimePicker like this:
jQuery('#datetimepicker').datetimepicker({
disabledDates: ['27/04/2022 14:00'],
format:'d/m/Y H:i'
});
However, this does not work. I can either only disable specific times for every day, or disable specific dates.
CodePudding user response:
That's because the jQuery plugin DateTimePicker's "disabledDates" only accepts and disables days. https://xdsoft.net/jqplugins/datetimepicker/
It looks like there is no such option for disabling specific times, you could work with only enabling specific times with https://xdsoft.net/jqplugins/datetimepicker/#allowTimes
jQuery('#datetimepicker').datetimepicker({
datepicker:false,
allowTimes:[
'01:00', '02:00', '03:00',
'04:00', ... , '15:00', '60:00'
]
});
If you would like to continue with jQuery DateTimePicker you would have to write your own function for it e.g.
jQuery('#datetimepicker').datetimepicker({
format:'d.m.Y H:i',
timepicker: true,
lang: 'en',
onGenerate:function(ct,$i){
//some function here to disable certain times
});
}
}
});
or you could use Bootstrap Datepicker which has an option to do exactly what you want https://getdatepicker.com/4/Options/#endisabledhours
CodePudding user response:
try this Reference
$(function () {
var disabledDate = ['2020-07-14', '2020-07-15','2020-07-16'];
$('#datetimepickerDemo').datetimepicker({
disabledDates: disabledDate
});
});