Simple date arithmetic in JavaScript

Adding and subtracting numbers from dates to calculate dates in the future
Date Created: 4th November 2007
Date Modified: 4th November 2007
Home > JavaScript > Date Arithmetic

Testing code seen in WebmasterWorld JS Forum:

Sample code to create cookie:

var exdate=new Date();
document.cookie="bNumber=" +escape("1_2_3")+ ";expires="+exdate.toGMTString());

[Read Cookie]

This works OK. Adding 1 to the day of the month, even if we're on the last day on the month (ie. 31st Oct), returns the date of the next day (eg. 1st Nov)