Select to view content in your preferred language

# How to create a looping Arcade expression with dates

713
2
06-15-2023 06:27 AM
Labels (2)
Regular Contributor

I have a data set where the data has to be processed within 28 days of a date field. I have four subcategories within this cycle:  First 12 days, First 17 days, First 20 days, and Last 8 days. Each time period within this cycle represents a different procedure that must be done. I know this:

if (DateDiff(Now(), Date(\$feature.<FieldName>), 'days') <= 12) {
return "First 12 Days" }
else if ....

But this isn't a closed loop. At the end of the cycle, whatever wasn't processed needs to restart the cycle. But of course the date in the date field will show it being more than 28 days later. How can I write an expression in the symbology area that will reset a point's symbology every 28 days without writing out an infinite number of days into the future?

Tags (4)
1 Solution

Accepted Solutions
MVP Frequent Contributor

var diff = DateDiff(Today(), \$feature.Field, "days")
var overdue = diff > 28
diff = diff % 28  // modulo operation: divide by 28 and take the rest

var period = When(
diff > 20, "Last 8 days",
diff > 17, "First 20 days",
diff > 12, "First 17 days",
"First 12 days"
)
return period + IIf(overdue, " (overdue)", "")

Have a great day!
Johannes
2 Replies
MVP Frequent Contributor

var diff = DateDiff(Today(), \$feature.Field, "days")
var overdue = diff > 28
diff = diff % 28  // modulo operation: divide by 28 and take the rest

var period = When(
diff > 20, "Last 8 days",
diff > 17, "First 20 days",
diff > 12, "First 17 days",
"First 12 days"
)
return period + IIf(overdue, " (overdue)", "")

Have a great day!
Johannes
Regular Contributor

Wow, that was a lot simpler than I was anticipating. Thank you so much!