I have some trouble with date manipulation in Javascript.
I have one variable which is firstDay, that’s date that I’m operating on.
To firstDay I add X days from one variable, and Y days from another:
var from_date = new Date(firstDay); // firstDay is a string with date: 2012/07/28
var to_date = new Date(firstDay);
var X = 1;
var Y = 5;
from_date.setDate(from_date.getDate() + X);
to_date.setDate(to_date.getDate() + Y);
So from_date now contains date 29.07.2012 and to_date is 02.08.2012. I don’t know why date changes properly, but months stay the same.
Where I make something wrong?
Copy & pasted your code, it worked as expected: http://jsfiddle.net/kDYdW/4/
The only differences is
firstDay, so I assume you have problem with that maybe.You also say that “months stay the same” but you reported to have July in
from_dateand June into_date(29.07.2012 and 02.06.2012).Update: added the proper revision of the jsfiddle