views:

107

answers:

1

Hi,

For some reason when i enter the following dates into the following fields it is returning an invalid date range and i am not sure why:

http://jsfiddle.net/mQRaj/3/

To replicate please enter the following in the 'From' date:

30/11/2009

and then this in the 'To' date:

7/9/2010

Bur if i enter 16/11/2009 and 7/9/2010 it does not throw an error and i am not sure what i am doing wrong.

Any explanation as to what i have done wrong?

+2  A: 

This is because javascript uses American formatting for dates, also 16/11/2009 doesnt work when I try it?

you will need to split the string (UK date formatting) by '/' and then put it into the correct formatting.

Like so:

var dateParts = from.split('/');

var newDate = new Date(dateParts[1] + "/" + dateParts[0] + "/" + dateParts[2]);
JamesStuddart
I was just about to say the same thing. I'd rather call them European formatted dates though!
Jonny Cundall
lol, ok European formatted :D
JamesStuddart
Cheers! Updated jsFiddle here: http://jsfiddle.net/mQRaj/4/
RyanP13