Alex Rivera | Logout

How to add days to Date?

Asked 2009-02-18T23:57:20.757
1795

How to add days to current Date using JavaScript? Does JavaScript have a built in function like .NET's AddDay()?

Edit
Report

1 Answer

63

Try

var someDate = new Date();
var duration = 2; //In Days
someDate.setTime(someDate.getTime() +  (duration * 24 * 60 * 60 * 1000));

Using setDate() to add a date wont solve your problem, try adding some days to a Feb month, if you try to add new days to it, it wont result in what you expected.

answered 2012-05-02T10:01:45.477

Your Answer