Friday, June 27, 2008

Add months to a date in java script

Here is a function addMonths to add months to a date in java script.
example for 6 months add to December 26, 2007:
Date.prototype.addMonths = function (n) {
var day = this.getDate();
this.setMonth(this.getMonth() + n);
return this;
}
var d = new Date(”December 26, 2007″);
alert(d.addMonths(6));

No comments: