I use this code to compare two dates, the date of today and the date in the list item. On the screen the dates look fine but when I check them in the debugger the dates are way off. Some are even one year ahead. Why does the code return a different date than what I see on the screen?
<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function (ctx) {
// get today's date
var today = new Date();
var rows = ctx.ListData.Row;
for (var i = 0; i < rows.length; i++) {
// get the date set in your date YourDateField
var itemDate = new Date(rows[i]['DueDate']);
var rowId = GenerateIIDForListItem(ctx, rows[i]);
var row = document.getElementById(rowId);
console.log("itemdate: " + itemDate);
if (row!=null&&itemDate <= today) {
row.style.backgroundColor = '#FF0000';
}
}
}
});
});
</script>
Does anyone have a clue?