<?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: Selecting Features by Date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378841#M29889</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seeing I don't know what back-end database is hosting your data, I can't offer a specific suggestion.&amp;nbsp; In general, dates and times are handled differently depending on the back-end database:&amp;nbsp; &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB" title="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB"&gt;SQL reference for query expressions used in ArcGIS—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Nov 2017 23:45:37 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2017-11-13T23:45:37Z</dc:date>
    <item>
      <title>Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378839#M29887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to select all the features in a feature class that have been edited in the past day. I'm using SelectLayerByAttribute_management and I keep getting an error on the SQL query and was hoping someone could give me a hand.&lt;/P&gt;&lt;P&gt;In the code below &lt;STRONG&gt;lyr&lt;/STRONG&gt; is the feature class being evaluated and &lt;STRONG&gt;MOD_DATE&amp;nbsp;&lt;/STRONG&gt;is the date field being checked.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;yesterday &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; timedelta&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
yesterdaysDate &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; yesterday&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%m/%d/%y %I:%M:%S"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

SQL_statement &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MOD_DATE &amp;gt;= 'yesterdaysDate'"&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"FEATURE_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByAttribute_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"FEATURE_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"NEW_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; SQL_statement&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:29:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378839#M29887</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2021-12-11T17:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378840#M29888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;SQL_statement &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MOD_DATE &amp;gt;= '"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;yesterdaysDate&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And, noting &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌'s comment below,&amp;nbsp; you may need to proceed your date with the word "date" (if using a file geodatabase, for example):&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;SQL_statement &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MOD_DATE &amp;gt;= date '"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;yesterdaysDate&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Nov 2017 22:39:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378840#M29888</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2017-11-13T22:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378841#M29889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seeing I don't know what back-end database is hosting your data, I can't offer a specific suggestion.&amp;nbsp; In general, dates and times are handled differently depending on the back-end database:&amp;nbsp; &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB" title="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB"&gt;SQL reference for query expressions used in ArcGIS—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Nov 2017 23:45:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378841#M29889</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-11-13T23:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378842#M29890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the underlying database, and what is the error?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Nov 2017 23:58:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378842#M29890</guid>
      <dc:creator>TinaMorgan1</dc:creator>
      <dc:date>2017-11-13T23:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378843#M29891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The feature classes are being pulled in through an SDE connection to an Oracel database.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2017 13:13:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378843#M29891</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-11-14T13:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Features by Date</title>
      <link>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378844#M29892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. The second statement worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2017 13:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-features-by-date/m-p/378844#M29892</guid>
      <dc:creator>MikeEdwards</dc:creator>
      <dc:date>2017-11-14T13:22:32Z</dc:date>
    </item>
  </channel>
</rss>

