<?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 Re: how to add multiple filters using query() of feature layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1431710#M10004</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try the code below as I believe the time_filter parameter wants a datetime object and when you use isoformat it converts it to a string.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;portal_item = gis.content.search(query="title:tankers", item_type="Feature Layer")
flayer = portal_item[3]
tankers = flayer.layers[0]

from datetime import datetime
# Convert the string to a datetime object
FromDate = datetime.strptime(from_date_str, '%d-%b-%Y')
ToDate = datetime.strptime(to_date_str, '%d-%b-%Y')

# Query the feature layer
query_result = tankers.query(where=f"trip_name = {'MCC'},time_filter=[FromDate, ToDate])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2024 14:18:01 GMT</pubDate>
    <dc:creator>MarkKinnaman</dc:creator>
    <dc:date>2024-05-10T14:18:01Z</dc:date>
    <item>
      <title>how to add multiple filters using query() of feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1422565#M9997</link>
      <description>&lt;P&gt;time = f"closingdate &amp;gt;= DATE '{from_date_str}' AND closingdate &amp;lt;= DATE '{to_date_str}'"&lt;BR /&gt;value = 'MCC'&lt;BR /&gt;field_filter = f"trip_name == '{value}'"&lt;BR /&gt;query_filter = f"{time_filter} AND {field_filter}"&lt;/P&gt;&lt;P&gt;# Query the feature layer&lt;BR /&gt;query_result = tankers.query(where=f"trip_name = 'MCC' AND time_filter={time}")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest what's wrong in the above code.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 14:24:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1422565#M9997</guid>
      <dc:creator>Manager_HMWSSBCDC</dc:creator>
      <dc:date>2024-05-09T14:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to add multiple filters using query() of feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1423638#M9999</link>
      <description>&lt;P&gt;Which language is this? I want to say python, but it is hard to tell from the looks of it.&lt;/P&gt;&lt;P&gt;If it is python, then you would need to adjust your dates to be equivalent to the following:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from datetime import datetime

FromDate = &amp;lt;FromDateField&amp;gt;.isoformat(timespec='seconds')
ToDate = &amp;lt;ToDateField&amp;gt;.isoformat(timespec='seconds')

time = f"closingdate &amp;gt;= {FromDate} AND closingdate &amp;lt;= {ToDate}"

# Query the feature layer
query_result = tankers.query(where=f"trip_name = {'MCC'} AND {time}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 17:05:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1423638#M9999</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-05-09T17:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to add multiple filters using query() of feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1429167#M10000</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for the reply. I wrote this using ArcGIS API Python&lt;/P&gt;&lt;P&gt;I followed according to your code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;portal_item = gis.content.search(query="title:tankers", item_type="Feature Layer")
flayer = portal_item[3]
tankers = flayer.layers[0]

from datetime import datetime
# Convert the string to a datetime object
FromDate = datetime.strptime(from_date_str, '%d-%b-%Y').isoformat(timespec='seconds')
ToDate = datetime.strptime(to_date_str, '%d-%b-%Y').isoformat(timespec='seconds')

time = f"closingdate &amp;gt;= {FromDate} AND closingdate &amp;lt;= {ToDate}"

# Query the feature layer
query_result = tankers.query(where=f"trip_name = {'MCC'} AND {time}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I got the following error message:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Unable to complete operation.
Query with count request failed.
(Error Code: 400)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;where as in documentation, the syntax is different&lt;BR /&gt;&lt;BR /&gt;query(where="trip_name='MCC'",time_filter=[&amp;lt;start_time&amp;gt;,&amp;lt;end_time&amp;gt;)&lt;BR /&gt;&lt;BR /&gt;I tried the above one too, its not throwing any error but considering only first parameter in where clause not considering time_filter parameter.&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 07:29:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1429167#M10000</guid>
      <dc:creator>Manager_HMWSSBCDC</dc:creator>
      <dc:date>2024-05-10T07:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to add multiple filters using query() of feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1431710#M10004</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try the code below as I believe the time_filter parameter wants a datetime object and when you use isoformat it converts it to a string.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;portal_item = gis.content.search(query="title:tankers", item_type="Feature Layer")
flayer = portal_item[3]
tankers = flayer.layers[0]

from datetime import datetime
# Convert the string to a datetime object
FromDate = datetime.strptime(from_date_str, '%d-%b-%Y')
ToDate = datetime.strptime(to_date_str, '%d-%b-%Y')

# Query the feature layer
query_result = tankers.query(where=f"trip_name = {'MCC'},time_filter=[FromDate, ToDate])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 14:18:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1431710#M10004</guid>
      <dc:creator>MarkKinnaman</dc:creator>
      <dc:date>2024-05-10T14:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to add multiple filters using query() of feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1457593#M10007</link>
      <description>&lt;P&gt;You do not need to use the datetime.strptime() function since python will automatically convert a datetime python object to a sql datetime object when you specify the actual datefield.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from datetime import datetime
Sample = datetime.now().isoformat(timespec='seconds')
print( Sample )
#printed result = '2024-05-13T08:42:27'&lt;/LI-CODE&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 12:44:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-multiple-filters-using-query-of-feature/m-p/1457593#M10007</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-05-13T12:44:17Z</dc:date>
    </item>
  </channel>
</rss>

