Looking over the previous questions and answers it appeared this should work :
var palindrome = new Date('2011-11-11');
var december = new Date('2011-11-11');
december.setDate(palindrome.getDate()+20);
//should be december, but in fact loops back over to Nov 1st)
my jsFiddle
is there a simple way to ensure that months are incremented correctly, or have I missed something obvious ?
The
getMonth()call returns a value between 0 and 11, where 0 is January and 11 is December, so 10 means November. You need to increment the value by 1 when using it in a string. If you simply output it as a string you’ll see that it has the correct date. Note I also had to change the starting date format. It didn’t seem to like2011-11-11so I made it11/11/2011. http://jsfiddle.net/9HLSW/