Bootstrap datepicker show selected default date

I am using bootstrap datepicker and I am applying the set date function .

t.,

$('.datepicker').datepicker('setDate', new Date(2011, 2, 5));

This works fine, but the specified date is not selected.

+4
source share
2 answers

After selecting a date using the method, you need to update to get the selected date in . setDatedatepickerdatepicker

Before:

enter image description here

$('#datepicker').datepicker('setDate', new Date(2011, 2, 5));
$('#datepicker').datepicker('update');  //update the bootstrap datepicker

Jsfiddle

Finally:

enter image description here

+12
source

I am using bootstrap datepicker. below code worked for me:

$('#my-datepicker').datepicker('setDate', 'now');
+1
source

All Articles