In my JavaScript code I have to variables (x and y) with datetime values. All of the following statements return false:
- x < y -> false
- x > y -> false
- x == y -> false
- x === y -> false
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.
I am using IE9.
Is there a different way to check if two datetime values are equal?
update (code) - I tried to extract some relevant parts, whole project is very big:
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 < data.length; i++) {
var d = data[i];
for (var key in d) {
if (d[key] && 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" && value) {
if (row > 0) {
if (data[row].VF < addDays(data[row - 1].VF, 2)) {
css = "error_cell";
}
}
}
if (columnID === "VU" || columnID === "VF") {
if (dataContext.VF && dataContext.VU) {
if (dataContext.VU <= dataContext.VF) {
css = "error_cell";
}
}
}
if (columnID === "Rate" && row < (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" && row < (strict_mode ? data.length - 1 : data.length - 2)) {
if (value === undefined || value === null) {
css = "error_cell";
}
}
if (columnID === "Rate" && value < 0) {
css = "error_cell";
}
//PROBLEM IN NEXT LINE
if (columnID === "VU" && row < data.length - 1 && dataContext.VU && data[row + 1] && 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;
}