How to limit minimum time in bootstrap datetimepicker

How to limit

I am trying to limit the time that the user can choose from this plugin: https://github.com/Eonasdan/bootstrap-datetimepicker

I looked at this site and Google on similar issues, but users usually ask for validation to work between one known period and another known period. e.g. 9:00 - 21:00 2015/03/09 9:00 - 2015/03/10 21:00. If the user enters the data at 2015/03/09 23:00, the check will go so, because the time is within these two minutes / maximum periods.

I need it to work, how the reservation system works, so that every day is limited between these times. for example, if the user selects 2015/03/09 23:00 or 2015/03/10 5:00, then the confirmation will not take place, it will take place only on any day from 9:00 to 21:00.

$('.datetimepicker').datetimepicker({ stepping: 30, minDate: moment({hour: 9, minute: 30}), format: 'YYYY-MM-DD HH:mm' }); 

Min begins the date for today is at 9:30 in the morning, but if I were to choose any day after today, I could choose, for example, 4am - nothing at 9:30 in the morning

+6
source share
1 answer

Use the enabledHours property:

 $('.datetimepicker').datetimepicker({ stepping: 30, enabledHours: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], format: 'YYYY-MM-DD HH:mm' }); 

Therefore, it should allow any hours between 9:00 and 20:30, but will not allow anything from 21:00. More details at http://eonasdan.imtqy.com/bootstrap-datetimepicker/Functions/#endisabledhours .

+2
source

Source: https://habr.com/ru/post/983531/


All Articles