1

Possible Duplicate:
Compare 2 dates with JavaScript
Compare two dates in JavaScript

I am new to jQuery and I want to compare two dates,

e.g. var date1 = '2011-01-12'; var date2 = '2011-01-15';

I tried but could't find a solution.

Community
  • 1
  • 1
user1073328
  • 13
  • 1
  • 6
  • This has already been answered here: http://stackoverflow.com/questions/658522/age-from-date-of-birth-using-jquery –  Jan 23 '12 at 10:23
  • Variables in your example are not really dates, but strings with formatted dates within. You can theoretically compare them using string comparison if the date format (Year first, then month, then day) will not change. – DRCB Jan 23 '12 at 10:27

1 Answers1

3

Because you've got the dates in a YYYY-MM-DD format, you can simply do string comparison;

if (date1 < date2) //
else if (date1 == date2) //

Aside from that, see the dupes.

Matt
  • 70,063
  • 26
  • 142
  • 172