I've tried searching for people with similar questions, but haven't found anything.
I have two dates in JavaScript, both set to the same value... Equality Testing fails on ==, but >= and <= evaluate true.
Below is the code I have in play:
var startDate = new Date( 2011, 7, 30, 0, 0, 0, 0 ); var dt = new Date( 2011, 7, 30, 0, 0, 0, 0 ); if( startDate == dt ) document.write('They Equal<br />'); if( startDate > dt ) document.write('Start Date is > dt<br />'); if( startDate >= dt ) document.write('Start Date is >= dt<br />'); if( startDate < dt ) document.write('Start Date is < dt<br />'); if( startDate <= dt ) document.write('Start Date is <= dt<br />'); if( dt == startDate ) document.write('They Equal<br />'); if( dt > startDate ) document.write('dt > startDate<br />'); if( dt >= startDate ) document.write('dt >= Start Date <br />'); if( dt < startDate ) document.write('dt < Start Date <br />'); if( dt <= startDate ) document.write('dt <= Start Date <br />'); document.write( dt ); document.write( '<br />'); document.write( startDate ); Has anyone encountered anything like this, or am I doing something fundamentally wrong?
I tested this is Internet Explorer (9), Firefox 5+, and Chrome.
Update:
So two people posted great answers to my problem, and I thank both of you: xdazz and DaveRandom. I had read an earlier post on stackoverflow.com on a similar question and a guy said that date objects could be compared like any others, and any other example I found always did a < or > type of compare, never a full equality so I wasn't able to make the connection as to why I was doing it wrong.
Thanks to you two, and the others that posted similar answers.