Applecow
Applecow

Reputation: 842

bootstrap datepicker default view date

I want to use the datepicker with a specific default date, but somehow this doesn't work:

<input class="cal-datepicker" data-provide="datepicker" data-date-format="dd/mm/yyyy" data-date-autoclose="true" data-date-today-highlight="true" data-date-default-view-date="01/01/2015">

How can I get it to work?

Upvotes: 0

Views: 7053

Answers (3)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48357

You could try this:

$('.cal-datepicker').datepicker("update", new Date());

Upvotes: 1

Laiacy
Laiacy

Reputation: 1600

I solved my problem by setting the 'useCurrent' property to 'false', and then set the date after initialization:

$('#datepicker').datepicker({
  useCurrent: false,
  format: 'dd/mm/yyyy'
});

$('#datepicker').datepicker('setDate', '01/01/2017');

Upvotes: 2

Damian Dominella
Damian Dominella

Reputation: 620

As this answer says, you have to use the setDate function of the datepicker library. Like this:

$('#datepicker').datepicker('setDate', new Date()); // = set to today

Upvotes: 5

Related Questions