Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating future date and formatting it

Status
Not open for further replies.

mais123

Programmer
Dec 26, 2007
36
US
Hi I need to create a date that is 21 days in the future and output it in this format: mm/dd/yyyy
I have this:
var d = new Date();
d.setDate(d.getDate() + 21);
var formattedDate = d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear()
alert(formattedDate);

I get 3/2/2008 for formatted date. However, when I output d variable I get the correct date in the future. Whats wrong with formatting?

Thnaks
 
I see the same thing:
the value of d is (correctly) April 3, 2008
but the value of d.getMonth() is 3 (should be 4).

That said, I have no idea why.

_________________
Bob Rashkin
 
Right, so April should be 4.

_________________
Bob Rashkin
 
Right, so April should be 4.

Nope, 0 based means it starts counting from 0:

0 - January
1 - February
2 - March
3 - April
etc...

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top