0

The following code does not compare two date.

var dateTextB=columns[0];
        var dateB = new Date(dateTextB);

        alert(dateA+' '+dateB);

        if (dateA==dateB)
        {
        // code
        }

        dateA= new Date(dateTextB);

That prints

Mon Aug 18 2014 23:30:00 GMT+0600 (Central Asia Standard Time)----------Mon Aug 18 2014 23:30:00 GMT+0600 (Central Asia Standard Time)

But Does not fulfill if condition. But prints same values sometimes.

I have tried if (dateA==dateB.getTime()) also.

Does anyone know what is wrong here?

tanvir
  • 317
  • 3
  • 13
  • to be safe in javascript you should always use `===` as comparison operator ([see](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons)) – Niklas Dec 08 '15 at 10:42
  • I have tried also. It did not work. – tanvir Dec 08 '15 at 10:59
  • I didn't say it was the solution. That's why I didn't post an answer. I just wanted to point out that this is the better operator for comparison with equal signs. – Niklas Dec 08 '15 at 11:00

1 Answers1

0

Did you tried

if (dateA.getTime()==dateB.getTime())
{
}
gurvinder372
  • 66,980
  • 10
  • 72
  • 94