Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap datepicker show default date selected

Im using bootstrap datepicker and I'm applying the set date function.

ie.,

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

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

like image 213
user2877992 Avatar asked Nov 18 '13 04:11

user2877992


People also ask

How do I change the default date in Datepicker?

$(". selector"). datepicker( {defaultDate:"+6"} );

How can I select current date in Datepicker?

You must FIRST call datepicker() > then use 'setDate' to get the current date. $(". date-pick").


2 Answers

After selecting the date using setDate method, you need to update the datepicker in order to get the selected date in datepicker.

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

like image 195
Praveen Avatar answered Sep 21 '22 19:09

Praveen


Im using bootstrap datepicker. below code worked for me:

$('#my-datepicker').datepicker('setDate', 'now');
like image 33
Ramanujam Allam Avatar answered Sep 21 '22 19:09

Ramanujam Allam