1

Possible Duplicate:
How to add months to a date in JavaScript?

What's the simplest way to add X numbers of months to a date object but keep the day number? My date's will always be the first of the month.

Examples: If my start date is "04/01/2012" and i need to add 4 months to it, the result will be "08/01/2012".

If my start date is "10/01/2012" and i need to add 4 months to it, the result will be "02/01/2013".

Community
  • 1
  • 1
David
  • 10,418
  • 17
  • 72
  • 122
  • 1
    Have you checked out the [Date Object](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date)? – epascarello Dec 17 '12 at 16:24

1 Answers1

4

Try something like date.setMonth(date.getMonth()+4). This will automatically catch the overflow condition and add one to the Year.

Richard Marr
  • 3,044
  • 1
  • 22
  • 31