-
Format the date
Hi all. I'm a javascript newbie and I'm stuck, so I've got some questions.
The first one is, I know you can store the date like this....
Code:
var mydate = new Date(2000, 11, 31);
But on the web page the person enters the date like this..... 31/12/2000. So is it possible to code it this way....
Code:
var mydate = new Date(31/12/2000);
I couldn't find anything on the internet, so maybe someone can offer some tips or help? Thanks.
-
Re: Format the date
You could try the datejs library. Link: http://code.google.com/p/datejs/
It allows various parsing and formatting ways. Check the sample usage section for more details.
:wave:
-
Re: Format the date
Are you getting the date as one string? If so, you can split by the char '/' and have your date in an array.
Code:
var date = "31/12/2000";
var date_array = date.split("/");
var day = date_array[0];
var month = date_array[1];
var year = date_array[2];
For more info: http://www.w3schools.com/jsref/jsref_split.asp