Alex
Alex

Reputation: 40395

Regex to compare 2 dates in javascript

is there a good regex expression that would be able to compare two dates like 3/27/2010 to 3/8/2010 to tell if the first date is greater then the second date?

I'd like to compare using javascript

Upvotes: 0

Views: 2017

Answers (2)

SLaks
SLaks

Reputation: 887305

It is almost impossible, and completely insane, to do this with a regular expression.

Instead, use Javascript's Date object:

if (new Date(str1) > new Date(str2))

Upvotes: 0

kennytm
kennytm

Reputation: 523214

if (new Date("3/27/2010") < new Date("3/8/2010")) {
   alert("something's wrong.");
}

Upvotes: 3

Related Questions