2

On v4.17.43

So I have a simple picker:

$('.datetimepicker .date-range-start').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    maxDate:moment().endOf('day')
})

and the default date is set in the html to something like '2016-10-31 00:00'

<input type="text" class="date-range-start" name="start" value="2016-10-31 00:00" />

But whenever you change the day with the picker, the time gets changed to the current time. How can I get it to STAY as 00:00 unless the user actually changes the time with the time part of the picker.

I found one person saying set useCurrent:'day' but thats not changing anything for me.

SpeedOfRound
  • 1,210
  • 11
  • 26
  • Can you add your html code and show how you set default date? Please note that [`useCurrent`](http://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent) option takes a boolean value, so to disable you have to use `useCurrent: false` instead of `'day'` – VincenzoC Oct 31 '16 at 17:29
  • When I say set default date, I mean I'm instantiating the datepicker on an input with a value of '2016-10-31 00:00'. I tried `useCurrent: false` aswell with no change. I read there was an option to put 'day' 'month' or 'year' in useCurrent that wasn't in the doc, but maybe it was deprecated . – SpeedOfRound Oct 31 '16 at 18:21
  • Ok, I'm sorry that `useCurrent: false` didn't help, anyway I think that adding the html code would help to find a solution. – VincenzoC Oct 31 '16 at 19:26

1 Answers1

2

You can set a defaultValue to the picker using data attribute instead of setting value, so you will have data-date-default-date on your input.

You can find more about data-* initialization here and here.

Here a working example:

$('.datetimepicker .date-range-start').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    maxDate: moment().endOf('day')
})
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/locale/en-gb.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>

<div class='col-sm-6 datetimepicker'>
    <input type="text" class="form-control date-range-start" name="start" data-date-default-date="2016-10-31 00:00" />
</div>

Please note that your example will work as you expect if you use version 4.17.37 of the datetimepicker, as shown in the following example. Maybe you can also consider downgrading to a previous version of the datetimepicker.

$('.datetimepicker .date-range-start').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    maxDate: moment().endOf('day')
})
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/locale/en-gb.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class='col-sm-6 datetimepicker'>
    <input type="text" class="form-control date-range-start" name="start" value="2016-10-31 00:00" />
</div>
Community
  • 1
  • 1
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
  • 1
    adding the attribute `data-date-default-date` instead of value give me exactly what I want, thanks! I find this to be pretty unintuitive though :/ – SpeedOfRound Nov 02 '16 at 17:34
  • I agree with you, the old version seems to act more _naturally_, anyway I'm happy you solved your issue. – VincenzoC Nov 02 '16 at 18:37