Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datepicker: how to set start and end date

How to set the opening date of a jQuery datepicker, as well as the start and end date. I tried this but the calendar still opens to July (today) and the dates outside the min and max are not greyed out?

$('#datepicker').datepicker({
    minDate: new Date('30/11/2014'),
    maxDate: new Date('03/05/2015'),
    setDate: new Date('30/11/2014')
});

See jsFiddle

like image 481
greener Avatar asked Dec 20 '22 13:12

greener


1 Answers

You are creating your date objects incorrectly. The javascript date object parameters are Year, Month, Day. However, the month parameter is zero indexed so make sure you subtract one. For more information, please check the Date object reference.

$('#datepicker').datepicker({
    minDate: new Date(2014, 10, 30),
    maxDate: new Date(2015, 2, 5),
    setDate: new Date(2014, 10, 30)
});

Live Demo

As Pluto has also mentioned, you can also format it in MM/DD/YYYY.

like image 153
Josh Mein Avatar answered Jan 09 '23 15:01

Josh Mein