Set initial value for datetimepicker bootstrap

Aydar Omurbekov picture Aydar Omurbekov · Oct 11, 2016 · Viewed 8.3k times · Source

I cant set initial value 2016-10-17T00:00:00.000+00:00 for the datetimepicker with format MMMM DD, YYYY.

http://jsfiddle.net/0Ltv25o8/3753/

How can I do that?

Answer

Alan Jurczak picture Alan Jurczak · Oct 11, 2016

Try writing the value in the format you specified:

<input type="text" class="form-control" id="datetimepicker2" value = "October 17, 2016" />

value = "October 17, 2016" is in "MMMM DD, YYYY" format.

Fiddle

EDIT: You can also pass the date in datetimepicker options:

date: 'October 17, 2016'

or

date: new Date(2016, 9, 17) //months start from 0, so October = 9

Whole constructor:

$('#datetimepicker2').datetimepicker({
  format: 'MMMM DD, YYYY',
  date: new Date(2016, 9, 17)
});

Updated fiddle