Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI DatePicker displaying wrong date

I've got a jquery UI DatePicker with the following parameters:

changeMonth: true,
changeYear: true,
yearRange: "-16:-1",
dateFormat: 'dd-mm-yy'

It correctly displays only years 1996 till 2011. However, when I select a date for the first time, it's strangely displayed as 08-03-2012. 2012 is not even an option for selection in the datepicker, but this is the date which is then produced in my text box.

If I then select a date once again, it's correctly displayed - this only occurs for the first time.

Any ideas?

like image 501
Dot NET Avatar asked Dec 04 '25 09:12

Dot NET


1 Answers

You can set a default date in your range like this:

<script type="text/javascript">
$(function() {               
    $("#birthdate" ).datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-16:-1",
        dateFormat: 'dd-mm-yy',
        defaultDate: '01-01-1996'
    });
});
</script>
like image 189
kleinohad Avatar answered Dec 05 '25 23:12

kleinohad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!