5

I want a picker to be set to a month in the future by default. This works fine:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

However, I also want the date to be not before tomorrow. So I try adding a minDate option:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      minDate: moment().add(1, 'd').toDate(),
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

However, now the default date is set to minDate (that is, tomorrow). Can I set a default date independently from the minimum date?

P_S
  • 325
  • 1
  • 3
  • 16

3 Answers3

20

Looking at the code on GitHub (line 1674) if you set the option useCurrent to false, your default may not be overridden:

 <script type="text/javascript">
   $(function () {
     $('#enddatepicker').datetimepicker({
       useCurrent: false,
       minDate: moment().add(1, 'd').toDate(),
       defaultDate: moment().add(1, 'M').toDate(),
       locale: 'de',
       format: 'DD.MM.YYYY'
     });
   });
 </script>
philreed
  • 2,497
  • 5
  • 26
  • 55
  • Thanks, that worked out for me! Would you say I still should raise an issue (at least for the situation to be explicitly documented)? – P_S Aug 05 '15 at 12:21
  • That's not a bad idea. If the documentation is amended then to clarify then others may not have the same issue. – philreed Aug 05 '15 at 15:46
0

I would raise an issue in github for this, as minDate should not override defaultDate. In the mean-time, all you can do is set the value explicitly:

$(function () {
    $('#enddatepicker').datetimepicker({
         minDate: moment().add(1, 'd').toDate(),
         locale: 'de',
         format: 'DD.MM.YYYY'
    });
     $('#enddatepicker').val(moment().add(1, 'M').format('DD.MM.YYYY'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<div class="container">
  <div class="row">
    <div class="demo col-xs-6">
       <input class="form-control" id="enddatepicker"/>
    </div>
  </div>
</div>
mccannf
  • 16,619
  • 3
  • 51
  • 63
  • `minDate` overrides `defaultDate` on purpose. If `min/maxDate` is before or after the `defaultDate` then `defaultDate` is an invalid date according to the options set – Eonasdan Aug 05 '15 at 20:38
-2

Try with Start Date property, after checked my jquery i found that has not minDate parameter but startDate parameter to handle minDate.it will work for you.

startDate :new Date(),

skype @lokesh7676 to get more help

  • -1 because... 1) The answer seems to be incorrect, AFAICT the API is still `minDate` and not `startDate`, perhaps you're confusing it with a different library? 2) Posting your Skype does not help visitors directly. StackOverflow is not intended for this, feel free to mention it on your profile. 3) The post lacks in formatting and grammar. – Aidiakapi Oct 13 '17 at 19:21