greener
greener

Reputation: 5069

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

Upvotes: 4

Views: 46555

Answers (2)

abubakkar tahir
abubakkar tahir

Reputation: 847

this is the easy way to do it what ever you date format is just pass to Date() it will set it automatically with required format.

var today = new Date(); 
var start = new Date('30/11/2014');
var end = new Date('03/05/2015');
$('#daterangepicker').daterangepicker({

         minDate:today,
         startDate:end,
         endDate:start
});

Upvotes: 2

Josh Mein
Josh Mein

Reputation: 28645

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.

Upvotes: 13

Related Questions