0

I am trying to manipulate a javascript date object, to increment it by one day:

var now = new Date(+1 day);

What are the javascript options for something like this...

EDIT: cheers

4
  • i see the same answer is given three times in 1 min. If that isn't fast! Commented Sep 28, 2010 at 21:59
  • 1
    @Tim I was used to waiting at least a half hour for a good programming answer. Now its rare that I go 10 minutes. I've never found any other Q&A community that gives answers of such high quality in so little time. :D Commented Sep 28, 2010 at 22:08
  • @Tim: Reputation and Badges have created a monster! Commented Sep 28, 2010 at 22:11
  • developer.mozilla.org/en/JavaScript/Reference/global_objects/… Commented Sep 29, 2010 at 0:03

3 Answers 3

3

Like this:

var now = new Date();
now.setDate(now.getDate() + 1);

setDate will correctly convert January 32 into February 1.

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

1 Comment

for some reason I had the impression this wasn't doing what it should be. Of course it was, and my error was elsewhere. cheers
1

Like this:

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

setDate will increase the current date with 1, hope this will help.

Comments

1

Some straightforward answers have been posted, but just do you know, W3Schools has a fantastic Javascript date object reference page.

2 Comments

…and is totally unrelated to W3C. Moreover, you should have posted this as a comment, not as an answer to this question.

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.