I'm using date.js to apply conditional formatting to a data grid. The data is parsed from a javascript array. All of my conditions are working correctly, except for this one:
if (val < today && val > '01-01-2000')
val is a string in MM-dd-yyyy format that I can't change. So I used date.js to convert today's date to a string in MM-dd-yyyy format and make the comparison. The problem is that 01-17-2014 is seen as less than 04-08-2013 - since it is comparing strings.
What's the best way around this?
I'd like to make it simple, which is why I converted to strings in the first place, but I'm not sure how to get around the year issue.
Thanks for any help!
var today = new Date.today().toString("MM-dd-yyyy");
var tomorrow = new Date.today().addDays(1).toString("MM-dd-yyyy");
var upcoming = new Date.today().addDays(7).toString("MM-dd-yyyy");
function eXcell_edncl(cell) {
this.base = eXcell_edn;
this.base(cell);
this.setValue = function(val) {
if (val.indexOf('ACT') >= 0) this.cell.style.backgroundColor="lightgreen";
else if (val.indexOf('PV') >= 0) this.cell.style.backgroundColor="lightgreen", this.cell.style.fontSize="20px";
else if (val.indexOf('YES') >= 0) this.cell.style.backgroundColor="lightgreen", this.cell.style.fontSize="20px";
else if (val < today && val > '01-01-2000') this.cell.style.backgroundColor="red";
else if (val == today) this.cell.style.backgroundColor="orange";
else if (val == tomorrow) this.cell.style.backgroundColor="yellow";
else if (val > tomorrow && val <= upcoming) this.cell.style.backgroundColor="lightyellow";
else this.cell.style.backgroundColor="";
this.cell.innerHTML = this.grid._aplNF(val, this.cell._cellIndex);
}
}