0

I have 2 datetimepicker on my application called Start Date & Due Date. If user selects 7th April as start date so end date should not be less then 7th, before 7th April dates should be disable. Since its datetimeepicker so both date & time should be taken into consideration.

$('.tsk_start').datetimepicker({
  format: 'yyyy-mm-dd hh:ii',
  //daysOfWeekDisabled:[5,6],
  autoclose: true,
  todayBtn: true,
  startDate: new Date(),
}).on('changeDate', function(selected){           

});

$('.tsk_end').datetimepicker({
  format: 'yyyy-mm-dd hh:ii',
  autoclose: true,
  todayBtn: true,
}).on('changeDate', function(selected){

});

I searched multiple questions here but unable to find proper documentation. I am using this plugin http://www.malot.fr/bootstrap-datetimepicker/index.php

Zack
  • 171
  • 2
  • 12

1 Answers1

0

As you state you're using this plugin, then it allows you to set the start date of the picker when an option is chosen, like this:

$('.tsk_start').datetimepicker({
  format: 'yyyy-mm-dd hh:ii',
  autoclose: true,
  todayBtn: true,
  startDate: new Date(),
}).on('changeDate', function(selected){           
  $('.tsk_end').datetimepicker('setStartDate', selected.date.valueOf());
});

$('.tsk_end').datetimepicker({
  format: 'yyyy-mm-dd hh:ii',
  autoclose: true,
  todayBtn: true,
})
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • Try using just `selected.date` – Rory McCrossan Apr 06 '17 at 13:30
  • Working fine now, but one question if I select start date 2017-04-07 00:00 but unable to select after 2017-04-07 00:00 till 2017-04-07 04:00, ,00:01,00:02,00:03 disabled on end date? 3 hours difference in end date – Zack Apr 06 '17 at 13:38
  • Glad you got it working. The implementation of the limit would be down to the picker. The easiest fix would be subtract 1 day from `selected.date` – Rory McCrossan Apr 06 '17 at 13:42
  • That's not how you subtract a day. Try this: http://stackoverflow.com/questions/1296358/subtract-days-from-a-date-in-javascript – Rory McCrossan Apr 06 '17 at 13:48