最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap datetimepicker startDate does not disable past dates - Stack Overflow

programmeradmin5浏览0评论

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
});

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
});
Share Improve this question edited Nov 25, 2015 at 12:14 Salman Arshad 273k84 gold badges444 silver badges534 bronze badges asked Oct 19, 2015 at 8:42 jingweijingwei 471 silver badge6 bronze badges 1
  • Maybe this answer will help you. – SHIVA Commented Feb 25, 2020 at 14:19
Add a ment  | 

4 Answers 4

Reset to default 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
});

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> 

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>
$('#DateFrom').datepicker('setStartDate', moment(new Date(2022,08,01)).format('DD/MM/YYYY'));
发布评论

评论列表(0)

  1. 暂无评论