Datetimepicker - Set Start Date and End Date ( Version Bootstrap4 bootstrap-date time picker )


CDN Link = https://getdatepicker.com/5-4/

* =====================
$('#start_date').datetimepicker({
defaultDate: moment(new Date()).format('DD.MMMM.YYYY hh:mm A'),
format: 'DD.MMMM.YYYY hh:mm A',
});
$('#end_date').datetimepicker({
defaultDate: moment(new Date()).format('DD.MMMM.YYYY hh:mm A'),
format: 'DD.MMMM.YYYY hh:mm A',
});

$('#start_date').on('change.datetimepicker', function(e) {
$('#end_date').data("datetimepicker").minDate(e.date._i);
});

$('#end_date').on('change.datetimepicker', function(e) {
$('#start_date').data("datetimepicker").maxDate(e.date._i);
});
===================== */

================== changelog update ================

when you trying to console.log(e.date._i); you see that it will print log twice every time you change date, first it will log old date and second time it will log new selected date, it cause no problem but when you trying some ajax or other call then it cause error because of multiple call at same time and JavaScript throw an error Uncaught RangeError: Maximum call stack size exceeded 
so, to avoid this you need to do thing as give below

$('#start_date').on('change.datetimepicker', function(e) {
     if($('#start_date').val()==e.date._i)
     {
        //alert('start date is '+e.date._i);
        $('#end_date').data("datetimepicker").minDate(e.date._i);
     }
});



Solution by: Shivani,Chirag,Kartik


Did you find this article useful?