-1

Hi Guys i need your expertise, the current code below will disable the current day and the past dates and what i'm trying to do is disable past days + current day and tomorrow code for disabling the current day disabledDates: [new Date()]

date picker that im using: https://eonasdan.github.io/bootstrap-datetimepicker/

$('#datetimepicker4').datetimepicker({ sideBySide: true, toolbarPlacement: "bottom", showClose: true, stepping: 30,  minDate: new Date(), disabledDates: [new Date()], useCurrent: false, icons: { close: 'glyphicon glyphicon-ok'} }); 

1 Answers1

0

In the minDate option, you can use moment's ability to specify after tomorrow's day like so :

minDate: moment(moment()).add(2, 'days')

After doing that you can remove disabledDates as it will be useless.

Working example below :

$(function() {
 $('#datetimepicker4').datetimepicker({ 
  sideBySide: true, 
  toolbarPlacement: "bottom",
  showClose: true, 
  stepping: 30,  
  minDate: moment(moment()).add(2, 'days'),
  useCurrent: false, 
  icons: { close: 'glyphicon glyphicon-ok'} 
 }); 
});
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/en-gb.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css">

<div class="container">
  <div class="row">
    <div class='col-sm-6'>
      <div class="form-group">
        <div class='input-group date' id='datetimepicker4'>
          <input type='text' class="form-control" />
          <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>
tcj
  • 1,645
  • 4
  • 13
  • 21