bootstrap datepicker show default date selected

14,462

Solution 1

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

Solution 2

Im using bootstrap datepicker. below code worked for me:

$('#my-datepicker').datepicker('setDate', 'now');
Share:
14,462

Related videos on Youtube

user2877992
Author by

user2877992

Updated on September 15, 2022

Comments

  • user2877992
    user2877992 about 1 year

    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.

  • sidonaldson
    sidonaldson almost 9 years
    Shame there isn't a option to do this rather that using the API.