How to set time picker only set time from 8:30 am to 8:30 pm in bootstrap-datetimepicker.js?
15,251
Solution 1
Here i solved my problem with this code:
$('.event_date').datetimepicker({
disabledTimeIntervals: [ [ moment().hour(0), moment().hour(8).minutes(30) ], [ moment().hour(20).minutes(30), moment().hour(24) ] ]
});
Solution 2
The docs are lacking here, but I found that the following items are the key.
Understand that the datetimepicker uses the moment.js library.
The disabledTimeIntervals takes an array of arrays that define a time range.
[ //outer array
[ start_time, end_time],
[ second_start_time, second_end_time]
]
The other key point is that when you define a moment, you need to include the hour and minute, leaving the defaults caused the filter to no work for me.
So if you wanted to define a shop that was open from 8:30 AM to 8:30 PM with a 30 minute, it would look as follows:
$('.event_date').datetimepicker({
disabledTimeIntervals: [
[moment().hour(0).minutes(0), moment().hour(8).minutes(30)],
[moment().hour(20).minutes(30), moment().hour(24).minutes(0)]
]
});
Author by
Suganthan Raj
Updated on July 20, 2022Comments
-
Suganthan Raj almost 2 years
HTML CODE:
<div class="form-group"> <label class="col-md-3 control-label" for="event_date">Start at</label> <div class="col-md-8"> <input id="event_start_date" name="event_start_date" type="text" placeholder="" class="form-control input-md event_date" required=""> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="event_date">End at</label> <div class="col-md-8"> <input id="event_end_date" name="event_end_date" type="text" placeholder="" class="form-control input-md event_date" required=""> </div> </div>`
JavaScript code:
$('#event_start_date').datetimepicker({ minTime: "08:30:00" });
I need to set timepicker start time as 8:30 AM to End time as 8:30 PM disable other time in time picker. How is possible please help?
-
Suganthan Raj almost 9 yearswhat's the value format to give in disableTimeIntervals
-
Suganthan Raj almost 9 yearsI Use disabledTimeIntervals: [{h: 0 }),{ h: 8 m: 30}, { h: 20 m:30 }, { h: 24 }] ,but i didn't get output
-
Suganthan Raj almost 9 yearsi Have got a error "option disabledTimeIntervals is not recognized!"
-
WebQube almost 9 yearsdo you have momentjs.com ? the variable has to be passed in that format.