Add day(s) to a Date object

Javascript

Javascript Problem Overview


> Possible Duplicate:
> How to add number of days to today's date?

I'm confused, I found so many different approaches, and which of them is actually correct?

So what is the correct way to add day(s) to a given Date?

Javascript Solutions


Solution 1 - Javascript

date.setTime( date.getTime() + days * 86400000 );

Solution 2 - Javascript

Note : Use it if calculating / adding days from current date.

Be aware: this answer has issues (see comments)

var myDate = new Date();
myDate.setDate(myDate.getDate() + AddDaysHere);

It should be like

var newDate = new Date(date.setTime( date.getTime() + days * 86400000 ));

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniLemmingView Question on Stackoverflow
Solution 1 - JavascriptnobodyView Answer on Stackoverflow
Solution 2 - Javascriptuser710502View Answer on Stackoverflow