HexaCrop
HexaCrop

Reputation: 4263

How to enable past dates in bootstrap datepicker

I am seeing a lot of questions in stack overflow regarding disabling past dates in bootstrap datepicker.

But i want to enable past dates in bootstrap datepicker.

Here is my code, and i don't know what i miss in this.

<input type='text' id="campaignCreateDate" data-date-format="dd-M-yyyy" class="form-control datePicker" name="proposed_start_date"/>

and this is my js script

$('#campaignCreateDate').datepicker({
        todayHighlight: true,
        autoclose: true,
        format: 'dd-M-yyyy',            
    }).datepicker('setDate',new Date());

I also tried with only a simple tag as below:

<input type='text' id="testStartDate" class="form-control datePicker" name="proposed_start_date"/>

without any code in js, but still the past dates are not shown.

i.e, if today is 04/12/2018, i am not able to select 03/12/2018 or any dates before that.

Upvotes: 1

Views: 2827

Answers (1)

sango
sango

Reputation: 161

Here is a fiddle i created to help you out.

var today = new Date();

$("#campaignCreateDate").datepicker({
  autoclose: true,
  format: 'dd-M-yyyy',
  endDate : today,
  todayHighlight: true
});

Upvotes: 1

Related Questions