user5534204
user5534204

Reputation:

Bootstrap datetimepicker startDate and EndDate

I want to allow only selectable date on calender, start date as today date and end date as 'end; below is my code, its not working pls advice

$(function() {
    var start = $('#start').val();
    var end = $('#end').val();

    $('#datepicker').datetimepicker(
        'setStartDate': today,
        'setEndDate':end);
 });

Upvotes: 4

Views: 15968

Answers (2)

Sumit Kumar Gupta
Sumit Kumar Gupta

Reputation: 2364

You should use minDate and maxDate for this features

$(function() {
    var start = '20-Aug-2019 10:05';  
    var end = '30-Sep-2019 10:05';

    $('#datepicker').datetimepicker({
        format : 'DD-MMM-YYYY HH:mm',
        minDate: today,
        maxDate:end,
     });
  });

Upvotes: 0

fjsuarez
fjsuarez

Reputation: 301

Read the docs at http://eonasdan.github.io/bootstrap-datetimepicker/Options/#mindate

There are no options called setStartDate or setEndDate.

You should use minDate and maxDate. For these options you can use date, moment, or string.

Here is a working jsfiddle with said options.

Edit. Also note that using new Date() will return the current time, so that should set your start date to today.

Upvotes: 5

Related Questions