Megha Paul
Megha Paul

Reputation: 385

Bootstrap datepicker not working with format and startdate

I am trying to set start date to 21 yrs back date and show the date in d/m/y format.The date is coming in d/m/y format but start date is not working

$('#date_of_birth').datepicker({
   autoclose: true,
   startDate: '2015-04-15',
   format: 'dd/mm/yyyy'
});

the input field is :

<input id="date_of_birth" type="text" placeholder="DD/MM/YYYY" data-provide="datepicker">

Please help.

Upvotes: 2

Views: 2388

Answers (2)

gouthamr
gouthamr

Reputation: 47

startDate is for the earliest date you can select. As @seth-mcclaine suggested, adding '-21y' works:

$('#date_of_birth').datepicker({
   autoclose: true,
   startDate: '-21y',
   format: 'dd/mm/yyyy'
});

Do you mean to use defaultViewDate instead? Ex:

$("#date").datepicker({ 
        autoclose: true,
        defaultViewDate: {
            month: '04',            
            day:'15',
            year: '2000'
        },
        format: 'dd/mm/yyyy' 
});

I used jQuery 1.11.0 and Bootstrap 3.3.1 to get this working.

Upvotes: 2

Seth McClaine
Seth McClaine

Reputation: 10040

Looking at the documentation here:

https://bootstrap-datepicker.readthedocs.org/en/latest/

And the following example:

$('.datepicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '-3d'
})

I would expect you to be able to do the following:

$('#date_of_birth').datepicker({
   autoclose: true,
   startDate: '-21y', //or '-21Y'
   format: 'dd/mm/yyyy'
});

Upvotes: 0

Related Questions