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
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
Share Improve this question asked Jul 22, 2014 at 17:34 greenergreener 5,06913 gold badges56 silver badges98 bronze badges 3- 3 You need to format dates the way we do it in the US, that's all. That is: MM/DD/YYYY. This is the modified jsFiddle: jsfiddle.net/pvRKe/1 – Pluto Commented Jul 22, 2014 at 17:38
- @Pluto duh! thanks - is the format client dependent? i.e. will the calendar not work on a non-US computer? – greener Commented Jul 22, 2014 at 17:41
- MM/DD/YYYY does seem to depend on the browser (I didn't see it in the specification). For using a string as a constructor for a Date object, these are official formats: tools.ietf.org/html/rfc2822#page-14 (or w3.org/TR/NOTE-datetime in ES5). However it makes more sense to use a different constructor instead of inputting a string. Here is the full documentation on the Date constructor (where I got my info from): developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – Pluto Commented Jul 22, 2014 at 17:55
2 Answers
Reset to default 13You 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.
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
});