Select to view content in your preferred language

Arcade date filter

494
2
10-30-2023 04:19 AM
Labels (1)
Lee_Butler
Occasional Contributor

Hi all,

I have two layers in may map:

  • A layer consisting of 10km grids
  • A layer for users to mark the location of insect traps placed in the field

I want to set up a count on the grid to show how many traps have been placed within that grid. I have tried the following Arcade but all I seem to get is errors.  Any idea on where I'm going wrong?

// Count all traps in grid square since 30/10/2023
var traps = FeatureSetById($map, "186ca9c0d27-layer-24")
var sql = "created_date >= '30/10/2023'"
var trapFilter = Filter(traps, sql)
var countTraps = Count(Intersects(trapFilter,$feature))
return countTraps

 

Thanks

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Can you share what kind of error you're getting?

Also, the format of the datetime string is probably where things are going wrong. It will depend somewhat upon on the underlying database system, but try writing your datetime in the format 'YYYY-MM-DD hh:mm:ss' and see if that works better.

- Josh Carlson
Kendall County GIS
0 Kudos
Lee_Butler
Occasional Contributor

Hi @jcarlson 

Thanks for the reply

If I write my expression like this:

// Count all traps in grid square since 30/10/2023
var traps = Filter(FeatureSetById($map, "186ca9c0d27-layer-24"), 'created_date >= "2023-10-30 00:00:00"')
var countTraps = Count(Intersects(traps, $feature))
return countTraps
 
I get this error:
Test execution error: Expected ["] or [A-Za-z0-9_.\x80-￿] but "-" found.. Verify test data.
 
If I switch the quotation marks around
// Count all traps in grid square since 30/10/2023
var traps = Filter(FeatureSetById($map, "186ca9c0d27-layer-24"), "created_date >= '2023-10-30 00:00:00'")
var countTraps = Count(Intersects(traps, $feature))
return countTraps
 
I get this error:
Test execution error: Unknown Error. Verify test data.
0 Kudos