Note that there are some explanatory texts on larger screens.

plurals
  1. POWrong result when checking if datetimes in JavaScript are equal
    text
    copied!<p>In my JavaScript code I have to variables (x and y) with datetime values. All of the following statements return false:</p> <ul> <li>x &lt; y -> false</li> <li>x > y -> false</li> <li>x == y -> false</li> <li>x === y -> false</li> </ul> <p>When I debug the code both x and y have the same value 'Sat Jan 1 12:00:00 UTC+0100 2011' and the same type.</p> <p>I am using IE9.</p> <p>Is there a different way to check if two datetime values are equal?</p> <p><strong>update (code)</strong> - I tried to extract some relevant parts, whole project is very big:</p> <pre><code>var data; //Dates are loaded from a webservice and returned as strings; they are parsed with the following function data = parseD(getDataFromService()); function parseD (data) { for (var i = 0; i &lt; data.length; i++) { var d = data[i]; for (var key in d) { if (d[key] &amp;&amp; d[key].toString().substring(0, 6) === "/Date\(") d[key] = new Date(parseInt(d[key].toString().substr(6))); } } return data; }; function getCssForCell(row, columnID, dataContext, value) { var css = ""; if (columnID === "VF" &amp;&amp; value) { if (row &gt; 0) { if (data[row].VF &lt; addDays(data[row - 1].VF, 2)) { css = "error_cell"; } } } if (columnID === "VU" || columnID === "VF") { if (dataContext.VF &amp;&amp; dataContext.VU) { if (dataContext.VU &lt;= dataContext.VF) { css = "error_cell"; } } } if (columnID === "Rate" &amp;&amp; row &lt; (strict_mode ? data.length - 1 : data.length - 2)) { //value for Rate must be assigned if (value === undefined || value === null) { css = "error_cell"; } } if (columnID === "VF" &amp;&amp; row &lt; (strict_mode ? data.length - 1 : data.length - 2)) { if (value === undefined || value === null) { css = "error_cell"; } } if (columnID === "Rate" &amp;&amp; value &lt; 0) { css = "error_cell"; } //PROBLEM IN NEXT LINE if (columnID === "VU" &amp;&amp; row &lt; data.length - 1 &amp;&amp; dataContext.VU &amp;&amp; data[row + 1] &amp;&amp; addDays(dataContext.VU, 1) != data[row + 1].VF ) { css = "error_cell"; } return css; } function addDays(date, days) { if (date) { var result = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours()); result.setDate(result.getDate() + days); return result; } return date; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload