maxDate and minDate not working in Jquery Datetime picker

1.2k Views Asked by At

All other attributes like format ,autoclose etc are working, but maxDate/minDate is not working.

Any help would be appreciated.

I am using bootstrap-datetimepicker

$(function() {
  $("#fdate").datetimepicker({
    format: 'yyyy-mm-dd',
    pickTime: false,
    startView: 'month',
    minView: 'month',
    autoclose: true,
    maxDate: '0'
  });
});
3

There are 3 best solutions below

0
On

Thanks to Nargis ,Rajesh & sibeesh for your Quick replies..

I Solved the problem ..

The problem was maxDate and minDate are attributes used in some other plugin (i think jquery datatime picker) . as I am using an old Bootstrap plugin ,The valid attributes are startDate and endDate

The worked code is below

$(function() {
    $( "#fdate" ).datetimepicker(
      {
         format: 'yyyy-mm-dd',
        pickTime: false,
        startView: 'month',
        minView: 'month',
        autoclose: true,   
         startDate: '-1d',//previous date
         endDate: new Date()//current date
      });
});
0
On

Isn't it suppose to be a date value. And also it seems you forgot to use the option in it.

$("#datepicker").datepicker('option', {minDate: <some date>, maxDate: <some date>});

Please have a look here.

0
On

-> At first see that have you imported the correct path for bootstrap-datetimepicker

$('#date').datepicker('option', { minDate: new Date(startDate), maxDate: new Date(endDate) });