Question

I have a Jquery UI datepicker on my site, but when i choose minDate and maxDate it adds a month to each variable, why is that and how do i fix it?

var startDate = new Date(2014, 2, 24);
var endDate = new Date(2014, 3, 24);

FIDDLE

Was it helpful?

Solution

If you date is taken from the database the easiest way to do so

var startDate = new Date(2014, 2, 24);
var endDate = new Date(2014, 3, 24);

startDate.setMonth(startDate.getMonth()-1);
endDate.setMonth(endDate.getMonth()-1);

OTHER TIPS

The month is zero-based, so add 1 to your chosen dates.

e.g.

var yourDate = new Date(2014, 3, 24); //would be 24 April 2014

In javascript, month count start from 0 and ends to 11 like:

0-Jan
1-Feb
2-Mar
3-Apr
4-May
5-Jun
6-Jul
7-Aug
8-Sep
9-Oct
10-Nov
11-Dec
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top