maximuz07
maximuz07

Reputation: 21

How do I restrict the Bootstrap datetimepicker from future dates?

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.

Upvotes: 1

Views: 352

Answers (1)

Andy
Andy

Reputation: 3012

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

Upvotes: 1

Related Questions