Add months to the date - Node.js Date

Node.js examples for Date:Month

Description

Add months to the date

Demo Code

/**/*from  w ww.j  av  a2  s. c  o m*/
 * Add months to the date
 * @param {date} value
 */
Date.prototype.addMonths = function(value)
{
    var n = this.getDate();
    this.setDate(1);
    this.setMonth(this.getMonth() + value);
    this.setDate(Math.min(n, this.getDaysInMonth()));
    return this;
};

Related Tutorials