I'm trying to create an expression in ArcGIS Online to label a polygon as "Closed" if today's date falls between the date in the ClosedDate field and the ReopenDate field but not to label anything if it is not between those dates or if either of those fields is blank/empty.
I can't have a field with "Closed" as there are popups and I don't want this text to confuse the user.
Thanks to all.
Solved! Go to Solution.
You can use this syntax
if ($feature.ClosedDate <= Today() && Today() <= $feature.ReopenDate) return "Closed";
You can use this syntax
if ($feature.ClosedDate <= Today() && Today() <= $feature.ReopenDate) return "Closed";
This work perfectly. Thanks, Ken.
And it automatically excludes any instances where the ClosedDate and/or ReopenDate fields are blank?
Would both of them be blank or would you have cases where only one is blank?
A better question is what would you want to see if one if blank and the other isn't.
they could both be blank because some fields aren't closed at any time in which case there is no label
The only case where it wouldn't return null with blank fields is if the ClosedDate was blank and the ReopenDate was after today. That would return "Closed". That's why I was asking what you would want to show if one field was blank but the other had a Date.
You can test the variants in the Arcade Playground with this code.
var ClosedDate = null;
//var ClosedDate = Date(2024,1,1);
var ReopenDate = Date(2024,1,14);
//var ReopenDate = null;
if (ClosedDate <= Today() && Today() <= ReopenDate) return "Closed";