0

All I want to do is to add 20 days to the current date. I need the results in mm/dd/yyyy format. Today is 05/15/2014 but this displays 05/35/2014 which of course is not a valid date.

var myDate = new Date();
alert((myDate.getMonth() + 1) + "/" + (myDate.getDate() + 20) + "/" +   myDate.getFullYear());
2

1 Answer 1

1

Use the setDate() method of your Date object, passing the current date plus the number of days to add.

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

alert((myDate.getMonth() + 1) + "/" + (myDate.getDate()) + "/" +   myDate.getFullYear());

Outputs

6/4/2014

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.