How to disable past dates from today in bootstrap datetimepicker? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

This question already has an answer here:

Unable to disable the past dates in bootstrap datetimepicker

HTML

<br/> <div class="row">     <div class="col-md-12">          <h6>Datetimepicker</h6>          <div class="form-group">             <div class="input-group date" id="datetimepicker">                 <input type="text" class="form-control" />  <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>             </div>         </div>      </div> </div> 

JavaScript

$(function () {     $('#datetimepicker').datetimepicker();  }); 

I also used startDate atrribute.But no use.

Fiddle here

回答1:

startDate option use in bootstrap-datepicker same option not mentioned anywhere in bootstrap-datetimepicker/Options/ doc it has minDate option for that

 $(function () {      $('#datetimepicker').datetimepicker({            minDate:new Date()       });  }); 

FIddle



回答2:

You can do it like this:

$(function () {        var date = new Date();        var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());          $('#datetimepicker').datetimepicker({          minDate: today        }); }); 

Another solution:

$(function () {     var date = new Date();   date.setDate(date.getDate()-1);    $('#datetimepicker').datetimepicker({     startDate: date   });   }); 


回答3:

I have used your fiddle and change it with following code which disables all the past dates ,its working perfectly.

Here is the Fiddle and CODE -

$(function () {             $('#datetimepicker').datetimepicker({             minDate : moment()             });         }); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!