1

I have a date time picker.I need to restrict future dates. For Eg:I want to restrict the future dates from current date.

Code Sample

     $('.datetimepicker').datetimepicker({
            format: 'mm-dd-yyyy',
            autoclose:true,
            endDate: "today",
            maxDate: today
        });

Anyone please help me.

maximuz07
  • 21
  • 4
  • Possible duplicate of [Disable future dates in Bootstrap 3 Datetimepicker](https://stackoverflow.com/questions/42974011/disable-future-dates-in-bootstrap-3-datetimepicker) – VincenzoC Jul 04 '18 at 22:00

1 Answers1

1

You can simply use a Date object from javascript, to limit the selection, for example:

$(function () {      
    var today = new Date();
    $('#datetimepicker1').datetimepicker({
        format: 'MM-DD-YYYY',
        minDate: today,
        maxDate: new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000) // 1 week from today
    });
});

The following formats are also allowed: string, Date, moment, boolean:false

working example: https://jsfiddle.net/amop9r3q/5/

docs: http://eonasdan.github.io/bootstrap-datetimepicker/Functions/#minmaxdate

Andy
  • 2,892
  • 2
  • 26
  • 33