5

i'm using Datetimepicker from https://eonasdan.github.io/bootstrap-datetimepicker/ for my project.

enter image description here

what i want to achieve is that the end should not be able to pick time earlier than the start.

$('#timePickerStart').datetimepicker({
    format : 'LT'
});
$('#timePickerEnd').datetimepicker({
    format : 'LT'
});

the datetimepicker has a function like that for date, but i don't know how to implement it in time.

thanks.

pat3ck029
  • 263
  • 1
  • 7
  • 19
  • I did. it uses function minDate and maxDate. and i tried using useCurrent: false but it has a bug, it only works the first time, when i change start time again after inputting the end time, it doesn't work anymore. – pat3ck029 Oct 16 '15 at 09:32
  • as you don't have any other requirement other then only to make sure the end time not before start time then hassle free solution is, use jQuery validation plugin or bootstrap validation plugin, just put the validation on the time fields and let them do the leg work for you. – Shehary Oct 16 '15 at 10:42

1 Answers1

2

You can disable certain time intervals with the disabledTimeIntervals property and function. It takes two moment objects in an array. The other way is disabling certain hours with the disabledHours property and disabledHours() function.

What you could do is this: when the user changes one of the pickers, run a callback. In this callback, you can use the date() function, to get the current moment, then set it for the other picker as an upper/lower bound with disabledTimeIntervals.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63