RyanP13
RyanP13

Reputation: 7743

jQuery datepicker date range throwing invalid date range error with valid dates

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?

Upvotes: 0

Views: 6131

Answers (1)

JamesStuddart
JamesStuddart

Reputation: 2611

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]);

Upvotes: 2

Related Questions