Forum Moderators: phranque

Message Too Old, No Replies

Javascript date problem

I hate javascript

         

Krapulator

3:48 am on Feb 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a javascript function which is used to calculate the difference between two dates.

The dates come in as a variable in the format 2003-01-28

I use a split function to replace the hyphens with commas as follows:

//CODE------------------------------------------------------------------
var arrive = arrivaldate;
var ariveArray = arrive.split('-');
var arrive = (ariveArray[0] + ',' + ariveArray[1] + ',' + ariveArray[2]);
//---------------------------------------------------------------------------

I then use them in a date function as follows:

var earlierdate = new Date(arrive);

However this causes an error (eg earlierdate = "nAn").
If I feed the date in manually it works fine eg:

var earlierdate = new Date(2003,01,28);

But using the variable does not work.

Why O Why?

dcheney

5:29 am on Feb 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Personally, when I do date calculations, I convert them to decimals first (such as 2003.14 for 20 Feb 2003). Makes the calculations very easy :-)

Krapulator

5:56 am on Feb 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool thanks for the advice.

I ended up solving the problem by using /'s instead of commas and changing the form to mm/dd/yyyy

txbakers

8:05 pm on Feb 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I love javascript. It all depends on what you can do with a tool.