-1

I have this code:

var d1 = new Date(Date.UTC(2011, 0, 1));
var d2 = new Date(Date.UTC(2011, 0, 1));

if (d1 == d2) { alert('Equals1'); }
if (d1 === d2) { alert('Equals2'); }
if (d1 < d2)  { alert('d1 < d2'); }
if (d1 > d2)  { alert('d1 > d2'); }

Could someone tell me WHY I can't comparing these two dates? You can run the script here: http://jsfiddle.net/vSL47/

These two dates should be equals, no?

Thanks

Dail
  • 4,622
  • 16
  • 74
  • 109
  • http://stackoverflow.com/questions/1657733/compare-two-dates-in-javascript Answers are already there.. – Vivek Chandra Feb 15 '12 at 10:02
  • You will also find a more generic answer here : http://stackoverflow.com/questions/1068834/object-comparison-in-javascript. It works for all kind of objects. – Francois Feb 15 '12 at 10:04

1 Answers1

0

For a more simple answer:

if (d1.toString() == d2.toString()) { alert('Equals1'); }

Works

RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75