How can I revise my script to compare lastInspectionDate and currentDate by month? I need to be able to determine if the last inspection was completed in the current month.
var lastInspectionDate = Date($datapoint["Inspected_Date"]);
var currentDate = Today();
var checkDates = ceil(DateDiff(currentDate, lastInspectionDate , 'days'));
var returnResults = When(checkDates <= 30, '#abf7b1',
checkDates > 30 && checkDates < 100, '#ff6863',
checkDates >= 100, '#',
'NA');
// Apply same background color to each cell in row
for (var cell in row.cells) {
row.cells[cell].backgroundColor = returnResults;
}
// Display icon
row.cells.Inspected_Date.iconName = When(checkDates <= 30, 'done',checkDates > 30 && checkDates < 100,'alert',checkDates > 100,'not_done', '');
return row
Solved! Go to Solution.
You can get the month values of both and compare them. You'll also want to make sure they are in the same year
var lastInspectionDate = Date($datapoint["Inspected_Date"]);
var currentDate = Today();
iif (Month(lastInspectionDate) == Month(currentDate) && Year(lastInspectionDate) == Year(currentDate), "Current month", "Not the current month");
You can get the month values of both and compare them. You'll also want to make sure they are in the same year
var lastInspectionDate = Date($datapoint["Inspected_Date"]);
var currentDate = Today();
iif (Month(lastInspectionDate) == Month(currentDate) && Year(lastInspectionDate) == Year(currentDate), "Current month", "Not the current month");