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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript convert string to a date 1

Status
Not open for further replies.

kathyc20

Programmer
Mar 7, 2001
96
CA

I have a variable called sTempDate which contains the value:

'03/08/2005'

How do I convert this string variable to a date?

Thanks.
 
Like this?
[tt]
var s="03/08/2005";
var odt=new Date(Date.parse(s))
alert(odt.getFullYear()+"\n"+odt.getMonth()+"\n"+odt.getDate());
[/tt]
 
Ahhh... but is that dd/mm/yyyy or is it mm/dd/yyyy? If you are getting unexpected results from the code that tsuji posted, then it could be that you are using a different date format.

Why, oh why did we ever let the Americans change everything [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Why, oh why did we ever let the Americans change everything

Cause you Brits were doing it wrong the whole time [wink]

-kaht

[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]
[banghead] [small](He's back)[/small]
 
It wouldn't have been so bad if we'd all moved to yyyy/mm/dd - at least then a "view by name" sort in a directory would handle dates nicely. I guess they weren't worrying too much about that back when they sailed to the US - short sighted decision if you ask me [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top