<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcade - Filter Feature Set by Date in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118552#M6079</link>
    <description>&lt;P&gt;I am trying to filter a feature set using a date field on ArcGIS Online. I need the filter to return a feature set of all records after a particular day. However, when I run the filter, I simply get back my starting feature set. In other words, it runs but it doesn't seem to be recognizing the filter expression that I've entered.&lt;/P&gt;&lt;P&gt;In the code below I'm creating two feature sets, one on line 4 and the other on line 5. Line 4 produces the feature set that I'd expect, but it's the filter on line 5 where I'm trying to get all records that have a date after the inspection date that doesn't seem to be working.&lt;/P&gt;&lt;P&gt;Is there additional formatting that I need to do to my inspectionDate variable to get it to evaluate correctly against my DATE field?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var inspectionDate = $feature.DATE
var client = $feature.CLIENT
var meter = $feature["SERIAL__"]
var fSetByMeter = OrderBy(Filter($layer, 'CLIENT = @client AND SERIAL__ = @meter'), 'DATE ASC');
var fSetCurrentDate = OrderBy(Filter(fSetByMeter, 'DATE &amp;gt; @inspectionDate'), 'DATE ASC')
return fSetCurrentDate&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Nov 2021 05:21:50 GMT</pubDate>
    <dc:creator>pmccord</dc:creator>
    <dc:date>2021-11-19T05:21:50Z</dc:date>
    <item>
      <title>Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118552#M6079</link>
      <description>&lt;P&gt;I am trying to filter a feature set using a date field on ArcGIS Online. I need the filter to return a feature set of all records after a particular day. However, when I run the filter, I simply get back my starting feature set. In other words, it runs but it doesn't seem to be recognizing the filter expression that I've entered.&lt;/P&gt;&lt;P&gt;In the code below I'm creating two feature sets, one on line 4 and the other on line 5. Line 4 produces the feature set that I'd expect, but it's the filter on line 5 where I'm trying to get all records that have a date after the inspection date that doesn't seem to be working.&lt;/P&gt;&lt;P&gt;Is there additional formatting that I need to do to my inspectionDate variable to get it to evaluate correctly against my DATE field?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var inspectionDate = $feature.DATE
var client = $feature.CLIENT
var meter = $feature["SERIAL__"]
var fSetByMeter = OrderBy(Filter($layer, 'CLIENT = @client AND SERIAL__ = @meter'), 'DATE ASC');
var fSetCurrentDate = OrderBy(Filter(fSetByMeter, 'DATE &amp;gt; @inspectionDate'), 'DATE ASC')
return fSetCurrentDate&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 05:21:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118552#M6079</guid>
      <dc:creator>pmccord</dc:creator>
      <dc:date>2021-11-19T05:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118567#M6080</link>
      <description>&lt;P&gt;Yeah, filtering by date can be iffy, as different DBMSs handle it differently.&lt;/P&gt;&lt;P&gt;Try converting your date to a string:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var inspectionDate = Text($feature.DATE, "Y-M-D")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 19 Nov 2021 07:24:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118567#M6080</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-11-19T07:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118638#M6081</link>
      <description>&lt;P&gt;Thanks for the response Johannes. When converting to a string, I'm still having the same problem where, on line 5 above, the filter returns all of my records from the Feature Set again. In other words, it doesn't seem like the filter that I'm applying is actually filtering anything out.&lt;/P&gt;&lt;P&gt;$feature.DATE is a date field, so wouldn't I need inspectionDate to also be a date rather than a string?&lt;/P&gt;&lt;P&gt;I've included a screen shot of some of the rows from my feature set:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pmccord_0-1637329369605.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27905i95A178A2A72EEA95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pmccord_0-1637329369605.png" alt="pmccord_0-1637329369605.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;inspectionDate is initially September 8, 2014, so I'm trying to filter for every record that's after September 8, 2014. As you can see from the screenshot above, all records, including September 8th, were returned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 13:46:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118638#M6081</guid>
      <dc:creator>pmccord</dc:creator>
      <dc:date>2021-11-19T13:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118649#M6083</link>
      <description>&lt;P&gt;Hard to say for sure, but I would guess that it's because &lt;STRONG&gt;DATE&lt;/STRONG&gt; is a r&lt;A href="https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15" target="_blank"&gt;eserved SQL keyword,&lt;/A&gt; which can throw off a query, as the database may be expecting something else when it sees that keyword, rather than assume it to be a field in your table.&lt;/P&gt;&lt;P&gt;What Arcade profile are you using, and where is the featureset coming from? Is it feasible to construct a featureset manually by populating a dict of features and rename the date field there?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 14:35:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1118649#M6083</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-11-19T14:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1119100#M6086</link>
      <description>&lt;P&gt;Great suggestion Josh. I converted my feature set to a dictionary, and while populating the date value of my dictionary, I converted the date to Unix time. I converted to Unix time as a result of stumbling on this post:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/developers-questions/arcade-dictionary-to-featureset/td-p/1047117" target="_blank"&gt;https://community.esri.com/t5/developers-questions/arcade-dictionary-to-featureset/td-p/1047117&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Once I had all the date values in Unix time, I converted my dictionary back to a feature set. I then converted the inspectionDate value to a Unix timestamp as I did above when creating the dictionary:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var inspectionDate = $feature.DATE
var start = ToLocal(Date(1970, 0, 01, 0, 0, 0, 0))
var dt = DateDiff(inspectionDate, start, 'milliseconds')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After doing this I was able to successfully filter for all dates after the inspection date.&lt;/P&gt;&lt;P&gt;I'm sure there's a more efficient way to do this, but I'm calling it good now that I'm getting the result I want. Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 04:26:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1119100#M6086</guid>
      <dc:creator>pmccord</dc:creator>
      <dc:date>2021-11-22T04:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - Filter Feature Set by Date</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1331828#M6765</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I was having the same problem. Assuming the the data are coming from a ArcGIS feature layer, when you filter a featureset, it is sending a request to REST API to a Query operation. After testing and checking some documentation, I found out that to define a "where clause" for query operation using a date field it is necessary to add DATE in front of date value. So In your case this could work:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fSetCurrentDate = OrderBy(Filter(fSetByMeter,'DATE &amp;gt; DATE @inspectionDate'), 'DATE ASC')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I don't know if using the DATE as a field name can have some issues of its own, as it is often a reserved keyword in DMBS system. Also, I didn't got it to work by passing date in variable such as "@insperction_date". But here is an example with my code which was working for me:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var read_out_date = Text($feature.collection_date, "Y-MM-DD");

// Define an sql query and filter the data
var sql = "collection_date &amp;lt; DATE '"+ read_out_date +"'";

var filteredDataSet = Filter(inputFeatureSet, sql);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally here is a link to a post about querying date fields at REST API:&lt;BR /&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/api-rest/data-management/querying-feature-services-date-time-queries/" target="_blank"&gt;https://www.esri.com/arcgis-blog/products/api-rest/data-management/querying-feature-services-date-time-queries/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 09:43:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-filter-feature-set-by-date/m-p/1331828#M6765</guid>
      <dc:creator>TórshavnarKommuna</dc:creator>
      <dc:date>2023-09-24T09:43:10Z</dc:date>
    </item>
  </channel>
</rss>

