Search code examples
javascripttwitter-bootstrapdatedatetimepicker

Bootstrap datetimepicker startDate does not disable past dates


I use bootstrap datetimepicker and I want to disable the past days but startDate option did not work:

var now = new Date();
var tomorrow = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1) + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
$('#end_at').datetimepicker({
    format: 'YYYY-MM-DD hh:mm:ss',
    startDate: tomorrow
});

Solution

  • You probably need to use the minDate option of the datetimepicker:

    var tomorrow = new Date();
    tomorrow.setDate(tomorrow.getDate() + 1);
    $("#end_at").datetimepicker({
        format: 'YYYY-MM-DD HH:mm:ss',
        minDate: tomorrow
    });