2

I use bootstrap datetimepicker and I want to disable the past days but startDate option did not work:

var now = new Date();
var tomorrow = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1) + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
$('#end_at').datetimepicker({
    format: 'YYYY-MM-DD hh:mm:ss',
    startDate: tomorrow
});
Salman A
  • 262,204
  • 82
  • 430
  • 521
jingwei
  • 47
  • 1
  • 6

4 Answers4

5

You probably need to use the minDate option of the datetimepicker:

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
$("#end_at").datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss',
    minDate: tomorrow
});
Salman A
  • 262,204
  • 82
  • 430
  • 521
  • dblclick day then close datetimepicker,How is this possible in Bootstrap Datetimepicker? – jingwei Oct 19 '15 at 09:45
  • This is working fine.but if I'm coming in this page in edit mode the value I set is not displaying,Any Idea? – Sribin Feb 03 '18 at 04:58
2

It's been a long time. The option minDate is deprecated. the new one is startDate

So you can use:

<script type="text/javascript">
    $(".form_datetime").datetimepicker({
        format: "dd MM yyyy - hh:ii",
        autoclose: true,
        todayBtn: true,
        startDate: "2013-02-14 10:00",
        minuteStep: 10
    });
</script> 
Raviteja
  • 3,399
  • 23
  • 42
  • 69
oneNiceFriend
  • 6,691
  • 7
  • 29
  • 39
0

startDate api will helps to disable past date

<script type="text/javascript">
     $(function() {
        $(".dates").datepicker({
        format:'dd-mm-yyyy',
        startDate:new Date(),
        autoclose:true
});
</script>
Naveen DA
  • 4,148
  • 4
  • 38
  • 57
0
$('#DateFrom').datepicker('setStartDate', moment(new Date(2022,08,01)).format('DD/MM/YYYY'));
rohit.khurmi095
  • 2,203
  • 1
  • 14
  • 12