Neilzxc Neilzxc - 2 months ago 24
jQuery Question

bootstrap 3 datetimepicker start date 2 weeks ahead

I want to start my datetimepicker 2weeks ahead.... here's my code

<div class="container">
<div class="row">
<div class='col-sm-3'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>

<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker();
});
</script>

Answer Source

Here you go with a solution https://jsfiddle.net/0Ltv25o8/5532/

$('#datetimepicker2').datetimepicker({
    defaultDate: moment().add('days', 14)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<div class="row">
    <div class="col-md-12">
      <input type="text" class="form-control" id="datetimepicker2" />
    </div>
</div>

I've used moment to add 14days.

You can add weeks as well instead of days

$('#datetimepicker2').datetimepicker({
  defaultDate: moment().add('weeks', 2)
});

For disabling the past dates

$('#datetimepicker2').datetimepicker({
   minDate: moment().add('days', 14)
});

Hope this will help you.

Please refer to jsFiddle as the code is not working in stackoverflow because of library link.