<?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: table.query Filter by variable in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/table-query-filter-by-variable/m-p/1131581#M6975</link>
    <description>&lt;P&gt;You can use f-strings to include a dynamic variable into a string. However, it's probably easier to create a direct SQL query searching for yesterday. I've added both examples:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# your code
now_dt = dt.utcnow()
yday_dt = now_dt - datetime.timedelta(days=1)
yesterday = yday_dt.strftime("%m/%d/%Y")

# create query with f-string
q_string = f"akt_datum='{yesterday}'"

# SQL
q_string = "akt_datum=CURRENT_DATE()-1" 

q_yday=table.query(where=q_string, out_fields = ["titel, typ, views, akt_datum, aenderung"]).sdf&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A final note, if akt_datum is a datetime field you may need to cast the field to DATE first for your query to work&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# SQL
q_string = "CAST(akt_datum AS DATE)=CURRENT_DATE()-1" &lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 07 Jan 2022 14:17:30 GMT</pubDate>
    <dc:creator>AdminGIS2</dc:creator>
    <dc:date>2022-01-07T14:17:30Z</dc:date>
    <item>
      <title>table.query Filter by variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/table-query-filter-by-variable/m-p/1131185#M6971</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a build a date as string from yesterday:&lt;/P&gt;&lt;P&gt;now_dt = dt.utcnow()&lt;BR /&gt;yday_dt = now_dt - datetime.timedelta(days=1)&lt;BR /&gt;yesterday = print(yday_dt.strftime("%m/%d/%Y"))&lt;/P&gt;&lt;P&gt;And I want to query a table text-column "akt_datum" with a Filter: where akt_datum=yesterday:&lt;/P&gt;&lt;P&gt;I tried this, but it doesnt work:&lt;/P&gt;&lt;P&gt;q_yday=table.query(where="akt_datum = yesterday", out_fields = ["titel, typ, views, akt_datum, aenderung"]).sdf&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;So my question is, how works the table.query Filter with a calculated variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and Greets&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 14:23:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/table-query-filter-by-variable/m-p/1131185#M6971</guid>
      <dc:creator>markkellermannBWB</dc:creator>
      <dc:date>2022-01-06T14:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: table.query Filter by variable</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/table-query-filter-by-variable/m-p/1131581#M6975</link>
      <description>&lt;P&gt;You can use f-strings to include a dynamic variable into a string. However, it's probably easier to create a direct SQL query searching for yesterday. I've added both examples:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# your code
now_dt = dt.utcnow()
yday_dt = now_dt - datetime.timedelta(days=1)
yesterday = yday_dt.strftime("%m/%d/%Y")

# create query with f-string
q_string = f"akt_datum='{yesterday}'"

# SQL
q_string = "akt_datum=CURRENT_DATE()-1" 

q_yday=table.query(where=q_string, out_fields = ["titel, typ, views, akt_datum, aenderung"]).sdf&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A final note, if akt_datum is a datetime field you may need to cast the field to DATE first for your query to work&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# SQL
q_string = "CAST(akt_datum AS DATE)=CURRENT_DATE()-1" &lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Jan 2022 14:17:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/table-query-filter-by-variable/m-p/1131581#M6975</guid>
      <dc:creator>AdminGIS2</dc:creator>
      <dc:date>2022-01-07T14:17:30Z</dc:date>
    </item>
  </channel>
</rss>

