Hi there, does anyone have a method of filtering a layer that shows features containing a date field which are within the next 'x' days. I know that there is already a date filter which can filter features within the last 'x' days but not within the next.
For example the layer has a field containing future dates and I would like only features to be selected by this field if it is within x days of todays date.
ID | Fruit | Date |
1 | Apple | 13/02/2022 |
2 | Pear | 14/02/2022 |
Any help would be much appreciated
Solved! Go to Solution.
I don't think this is possible using the regular layer filter in the webmap, but you can tweak the definition expression for the required layer in the web map using ArcGIS Online Assistant (or update the web map via REST interface). You can use any supported SQL statement here such as
DateField BETWEEN CURRENT_DATE() AND CURRENT_DATE() + x
Be aware this makes it impossible to further edit the expression in the webmap interface, you will get an error there if you try to.
Ah. In that case:
var start_date = Today()
var end_date = DateAdd(Today(), 5, "days")
var test_date = $feature.DateField
return test_date >= start_date && test_date <= end_date
Before:
After applying the Arcade expression:
After hiding the false features:
Note that this approach will probably be slower than just filtering out the undesired features from the layer (see HuubZwart's answer).
var start_date = Text(Today(), "Y-MM-DD") // Today: 2022-02-11
var end_date = Text(DateAdd(Today(), 5, "days"), "Y-MM-DD") // Today +5 days: 2022-02-16
var fs = FeatureSetBy*(...)
var future_records = Filter(fs, "DateField BETWEEN @start_date and @end_date")
Hi Johannes,
Thank you for your reply, I forgot to mention I was trying to do this in Mapviewer. I tried the expression above but the function 'Filter' cannot be used within the symbology.
Ah. In that case:
var start_date = Today()
var end_date = DateAdd(Today(), 5, "days")
var test_date = $feature.DateField
return test_date >= start_date && test_date <= end_date
Before:
After applying the Arcade expression:
After hiding the false features:
Note that this approach will probably be slower than just filtering out the undesired features from the layer (see HuubZwart's answer).
Thank you Johannes!
I don't think this is possible using the regular layer filter in the webmap, but you can tweak the definition expression for the required layer in the web map using ArcGIS Online Assistant (or update the web map via REST interface). You can use any supported SQL statement here such as
DateField BETWEEN CURRENT_DATE() AND CURRENT_DATE() + x
Be aware this makes it impossible to further edit the expression in the webmap interface, you will get an error there if you try to.
Thank you HubbZwart, This has worked 🙂
Hi HuubZwart,
Thank you for this. Having tried this it works when viewing on Mapviewer but when trying to load this map on Field Maps it does not load the layer at all. Does this method work on Field Maps?
It helped me a lot. Thanks.