3

This is my datepicker field:

<div class="form-group">
              <label for="exampleInputBday">Birthday</label>
              <input type="text" name="bday" class="datepicker" required>
            </div>

This is my javascript:

$(function(){
        $('.datepicker').datepicker({
            startDate: '-3y',
            'format' : 'mm/dd/yyyy',
            autoclose: true
            })
        })
 })

When I open the datepicker, the start date is the current date! How to solve?

6
  • what do you mean by startDate? jQuery's datepicker widget doesn't such an option. do you mean minDate?
    – gdoron
    Commented Sep 17, 2013 at 20:04
  • The earliest date that may be selected; all earlier dates will be disabled. Is 'datepicker for boostrap' -> eternicode.github.io/bootstrap-datepicker
    – user2297392
    Commented Sep 17, 2013 at 20:06
  • did you try startDate: '-1095',
    – adeneo
    Commented Sep 17, 2013 at 20:09
  • Thanks, but not worked...
    – user2297392
    Commented Sep 17, 2013 at 20:13
  • Not sure I get it, startDate sets the earliest date that may be selected; all earlier dates will be disabled. Is this not what you're trying to do? If not, you should read the documentation, all you have to do is set the value of the element to whatever date you choose ?
    – adeneo
    Commented Sep 17, 2013 at 20:34

1 Answer 1

2

This should do the trick. When you are defining the date picker, you can use setDate option:

$(".datepicker").datepicker("setDate", "10/12/2013");
4
  • That's exactly what I need, but I adapted it to my project and still not working = / The code is identical to yours!
    – user2297392
    Commented Sep 17, 2013 at 20:30
  • @JuninhoChr send me your code, may be I can see what is the problem. Commented Sep 17, 2013 at 20:31
  • 1
    Ths issue of course is that the two of you are working with different datepickers, the OP is using the bootstrap datepicker while this answer uses the jQuery UI datepicker ?
    – adeneo
    Commented Sep 17, 2013 at 20:39
  • Started using the jQueryUI datepicker and it worked! Thank you!
    – user2297392
    Commented Sep 17, 2013 at 20:59