0

I've a problem with date in Javascript. I need to increase by 1 day a date and I'm using this:

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

but when is the 30th of june the increased date will be the 31th of june and not the 1st of lst of july.

how can I obtain a correct increased data???

0

3 Answers 3

3

No it won't. Try this snippet, works just fine.

var myDate = new Date();
myDate.setDate(30); // it's June as of the writing of this question
                    // so we're setting it to June 30th.
myDate.setDate(myDate.getDate() + 1);
alert(myDate)

Update: I tried this in IE, Firefox, Chrome and Safari and it worked just fine.

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

2 Comments

you're right, I'm so stupid, my script were grabbing the wrong month value and he print me 31th of jly not june XD
Hope the rest of the day goes smoother.
1

How about setting time of the myDate:

myDate.setTime(myDate.getTime() + 24 * 60 * 60 * 1000)

Comments

0

Date manipulation can be hard - use a library like Datejs to do the hard work for you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.