Set Default Date Bootstrap Datepicker

This works for me after a long hours of search , This solution is for Bootstrap datetimepicker version 4. when you have to set the default date in input field.

HTML

"input type='text' class="form-control" id='datetimepicker5' placeholder="Select to date" value='<?php echo $myDate?>'// $myDate is having value '2016-02-23' "

Note - If You are coding in php then you can set the value of the input datefield using php, but datetimepicker sets it back to current date when you apply datetimepicker() function to it. So in order to prevent it, use the given JS code

JAVASCRIPT

<script>
$('#datetimepicker5').datetimepicker({
    useCurrent: false, //this is important as the functions sets the default date value to the current value 
    format: 'YYYY-MM-DD'
});
</script>

You can do:

$('#dob').datepicker('setDate', new Date(2006, 11, 24));
$('#dob').datepicker('update');
$('#dob').val('');

Fiddle Demo


If you want to make the change global, look for the following in bootstrap-datepicker.js:

function UTCToday(){
var today = new Date();
return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());

and hard code in your date, for example:

function UTCToday(){
var today = new Date();
return UTCDate(2006, 00, 01);

Which will open on 1 January 2006. Note that for some reason January is '00' rather than '01'.


Above accepted solution is staled, To help others who has the newest files, if you have Version 4 or newer, and you want to call a method, here is an example for bootstrap datetimepicker method :

$('#eventDate').data("DateTimePicker").date(moment(date).format('YYYY-MM-DD'));

bootstrap.datetimepicker format Option sample :

 $('#eventDate').datetimepicker({ format: 'YYYY-MM-DD' });

for more see here (but without valid sample :) ): http://eonasdan.github.io/bootstrap-datetimepicker/Options/