tags:

views:

81

answers:

3

hello, 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???

+3  A: 

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.

altCognito
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
d3vilkiss
Hope the rest of the day goes smoother.
altCognito
A: 

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

RichieHindle
+1  A: 

How about setting time of the myDate:

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

Svitlana Maksymchuk