Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 16
    Note: this resets time to 00:00:00 (can be an issue or not) Commented Feb 20, 2013 at 11:45
  • 1
    Doesn't work on the last day of any month, as you say. Makes this unusable on 12 days of the year. Sounds like a nightmare to debug!!! Commented Oct 14, 2013 at 10:59
  • 8
    No Drew, it is usable for all days on year. You can put date offset bigger than 31 or month offset bigger than 12 and this function will recalculate it as day in next month or month in next year. So for example: nextday=new Date(oldDate.getFullYear(),oldDate.getMonth(),oldDate.getDate()+40); is perfectly well code. Commented Nov 11, 2013 at 7:30
  • there is getMonth()+22 - what you think will it work!? Commented Jun 11, 2015 at 11:20
  • 1
    I Agree, use this way. We just had a bug because of daylight saving time because we were using setDate. Commented Apr 11, 2017 at 6:41