Select to view content in your preferred language

(Arcade) How do I project the next inspection date?

480
1
Jump to solution
03-20-2024 06:37 AM
Labels (3)
neomapper
Frequent Contributor

I have grids with a hardcoded last inspection date and an interval field specifying an inspection every 3 months. How can I calculate the next projected inspection date based on the current date and when the last inspection occurred? My objective is to provide just the upcoming projected inspection date going forward for every year.

 

neomapper_0-1710941333936.png

 

 

// Get the current month based on today date;
var currentdate = Today();
var currentISOMonth = ISOMonth(currentDate);
// decode the month as an integer;
var decode_current = Decode(currentISOMonth, 1, "Jan", 2, "Feb", 3, "Mar", 4, "Apr", 5, "May", 6, "Jun", 7, "Jul", 8, "Aug", 9, "Sep", 10, "Oct", 11, "Nov", 12, "Dec", "missing data");

// Get the last inspection month (Show as a (Integer) value);
var lastinspectiondate = Date($feature.lastinspection); 
var lastMonISO = ISOMonth(lastinspectiondate);
// Add projections for the rest of the year (Occurs ever 3 months)
var oneMonISO = When(lastMonISO + 3 < 12, lastMonISO + 3, lastMonISO - 12 + 3);
var twoMonISO = When(oneMonISO + 3 < 12, oneMonISO + 3, oneMonISO - 12 + 3);
var threeMonISO = When(twoMonISO + 3 < 12, twoMonISO + 3, twoMonISO - 12 + 3);

// Get the last inspection month (Show as a (Text) value);
var decode_last_Month = Decode(lastMonISO, 1, "Jan", 2, "Feb", 3, "Mar", 4, "Apr", 5, "May", 6, "Jun", 7, "Jul", 8, "Aug", 9, "Sep", 10, "Oct", 11, "Nov", 12, "Dec", "missing data");
//
var decode_Next_First = Decode(oneMonISO, 1, "Jan", 2, "Feb", 3, "Mar", 4, "Apr", 5, "May", 6, "Jun", 7, "Jul", 8, "Aug", 9, "Sep", 10, "Oct", 11, "Nov", 12, "Dec", "missing data");
var decode_Next_Second = Decode(twoMonISO, 1, "Jan", 2, "Feb", 3, "Mar", 4, "Apr", 5, "May", 6, "Jun", 7, "Jul", 8, "Aug", 9, "Sep", 10, "Oct", 11, "Nov", 12, "Dec", "missing data");
var decode_Next_Third = Decode(threeMonISO, 1, "Jan", 2, "Feb", 3, "Mar", 4, "Apr", 5, "May", 6, "Jun", 7, "Jul", 8, "Aug", 9, "Sep", 10, "Oct", 11, "Nov", 12, "Dec", "missing data");

return 
"\n" +"Last Inspection occurred on: " + decode_last_Month + " | " + lastMonISO
+ "\n" + "Next Inspection: " + decode_Next_First  + " | " + oneMonISO
+ "\n" + "Next Inspection: " + decode_Next_Second  + " | " + twoMonISO
+ "\n" + "Next Inspection: " + decode_Next_Third + " | " + threeMonISO
+ "\n" + "current date: " + decode_current + " | " + currentISOMonth
+ "\n" + "Our next inspection will be: " 

 

 

 

neomapper_1-1710940807251.png

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

It's easier than you think! There's a function, DateAdd, which can add a specified interval to a given date. You can also use the Text function to apply your preferred formatting to a datetime value.

var last_insp = $feature['lastinspection']

var next_insp = DateAdd(last_insp, 3, 'months')

return `Next Inspection: ${Text(next_insp, 'MMM | D')}`

 

- Josh Carlson
Kendall County GIS

View solution in original post

1 Reply
jcarlson
MVP Esteemed Contributor

It's easier than you think! There's a function, DateAdd, which can add a specified interval to a given date. You can also use the Text function to apply your preferred formatting to a datetime value.

var last_insp = $feature['lastinspection']

var next_insp = DateAdd(last_insp, 3, 'months')

return `Next Inspection: ${Text(next_insp, 'MMM | D')}`

 

- Josh Carlson
Kendall County GIS