4

So I have one input with date+time value (getting values from DB) and I am using jQuery Datetime picker to change date/time.

Here is my input

<div class="input-group form-group td-350">
  <div class="input-group date" id="datetimepicker1">
    <input type="text" name="new_preffered_date" class="form-control datetimepickers" value="<?= $item->customer_preferred_date->i18nFormat('dd.MM.YYYY HH:mm', 'Europe/Vienna') ?>"/>
    <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
  </div>
</div>

And here is my Datetimepicker configuration:

<script type="text/javascript" src="/vendors/bower_components/moment/min/moment-with-locales.js"></script>
<script type="text/javascript" src="/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">
    $('.datetimepickers').each(function () {
      $(this).datetimepicker({
        daysOfWeekDisabled: [0, 6],
        format: 'DD.MM.YYYY HH:mm',
        locale: 'de',
        minDate: new Date(),
      });
    });
</script>

With this configuration, Datetimepicker take as default value always date time from now. If I delete daysOfWeekDisabled option than I can see real date/time from database in input.

Info: My date from database is not weekend and is newer as now().

So my question is, how can I use DateTime picker with daysOfWeekDisabled option and as default value show date from database?

Documentation of Datetime picker is http://eonasdan.github.io/bootstrap-datetimepicker/Options/#daysofweekdisabled

VincenzoC
  • 30,117
  • 12
  • 90
  • 112
JohnWayne
  • 651
  • 9
  • 28
  • Are you sure that a date from your database has the `'DD.MM.YYYY HH:mm'` format? Did you try to remove `minDate` field? By the way, the last comma is excess. – Alexander Jun 01 '17 at 13:27
  • Yes, I am converting that day, and if I remove daysOfWeekDisabled option then everything is find, also I have tried to remove other options (one by one) and result is same. Its really wierd... – JohnWayne Jun 01 '17 at 13:30
  • 1
    Try to set [`useCurrent`](https://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent) to false. Has it helped? – Alexander Jun 01 '17 at 14:13
  • @Alexander it really helps, thank you :) – JohnWayne Jun 01 '17 at 14:15

2 Answers2

4

Set the useCurrent property to false. It will set the picker to the selected date/time instead of current.

Alexander
  • 4,420
  • 7
  • 27
  • 42
0

In your code you do not need to use each loop you can direct use like this

  $(".datetimepickers").datetimepicker({
    daysOfWeekDisabled: [0, 6],
    format: 'DD.MM.YYYY HH:mm',
    locale: 'de',
    defaultDate: "11/1/2013",//pass your database date
    minDate: new Date(),
  });
Jay
  • 703
  • 9
  • 21
  • I have already try this, and using defaultDate: today.getDate()+2 but default date is always now() if I use daysOfWeekDisabled: [0, 6], – JohnWayne Jun 01 '17 at 13:31