Select to view content in your preferred language

(Arcade) Check if last inspection is current month

640
1
Jump to solution
08-05-2022 07:53 AM
neomapper
Frequent Contributor

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

 

 

Tags (3)
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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");

 

View solution in original post

1 Reply
KenBuja
MVP Esteemed Contributor

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");