Having a puzzling issue when attempting to compare two date strings within my Angular Controller. It seems that the comparison is yielding unexpected results. To explain, I first convert today's date to a string ("2/5/2016") and then proceed to use it as a reference point for comparing with other inputted string dates. Below is the snippet of code in question:
function deleteTableRows(table) {
var year = getToday.getFullYear();
var month = getToday.getMonth() + 1;
var day = getToday.getDate();
var currentDate = month + "/" + day + "/" + year;
var qtr4 = '12/31/' + year;
var qtr3 = '9/30/' + year;
for (var i = table.length - 1; i >= 0; i--) {
if (currentDate < qtr4) {
if (table[i].intYear == year && table[i].intQuarter == 4) {
table.splice(i, 1);
}
}
if (currentDate < qtr3) {
if (table[i].intYear == year && table[i].intQuarter == 3) {
table.splice(i, 1);
}
}
}
};
The confusion arises when comparing currentDate ('2/5/2016') against qtr4 ('12/31/2016'). Surprisingly, the if statement evaluates to FALSE, indicating that 2/5/2016 is NOT less than 12/31/2016. However, when comparing currentDate against qtr3 ('9/30/2016'), the second if statement returns TRUE, suggesting that 2/5/2016 is indeed less than 9/30/2016. This behavior leaves me puzzled, as I suspect there might be a simple oversight on my end. If you have any insights or suggestions, they would be greatly appreciated!