<?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: Select Layer by Attribute issues in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296142#M22876</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/people/Dan_Patterson"&gt;Dan_Patterson&lt;/A&gt;, I wonder if you know how to query for data from the last 365 days using a date field?&amp;nbsp; Thank you!&amp;nbsp; -Shelby&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Oct 2017 17:59:50 GMT</pubDate>
    <dc:creator>ShelbyHines</dc:creator>
    <dc:date>2017-10-24T17:59:50Z</dc:date>
    <item>
      <title>Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296137#M22871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to 1) Select by Attribute and 2) overwrite a feature class with selected features.&amp;nbsp; Below is the script that I'm trying as a start.. and am getting an error related to Select by Attribute.&amp;nbsp; Ultimately, need to select last 365 days of data (not Baker neighborhood) and overwrite a feature class.. on a daily basis.&amp;nbsp; Thank you in advance for any assistance!&amp;nbsp; Shelby&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Description: Extract features to a new feature class based on an attribute query&lt;BR /&gt;# Import system modules&lt;BR /&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Make a layer from the feature class&lt;BR /&gt;arcpy.MakeFeatureLayer_management ("D:/pd/crimeD.gdb/dencrime", "crimelayer")&lt;/P&gt;&lt;P&gt;# Select all crimes that happened in Baker&lt;BR /&gt;arcpy.SelectLayerByAttribute_management ("crimelayer", "NEW_SELECTION", ' "NEIGHBORHOOD_ID" = baker ')&lt;BR /&gt;# Write the selected features to a new featureclass&lt;BR /&gt;arcpy.CopyFeatures_management("crimelayer", "Bakercrime")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 05:08:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296137#M22871</guid>
      <dc:creator>ShelbyHines</dc:creator>
      <dc:date>2017-10-24T05:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296138#M22872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With the shell script what is the error just in case&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;there is an error in the script and more importantly&lt;/LI&gt;&lt;LI&gt;it wouldn't work in the first place because what you are querying doesn't exist&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Secondly...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;how is the time data stored?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;is it in a field?&lt;/LI&gt;&lt;LI&gt;sequential values?&lt;/LI&gt;&lt;LI&gt;is it a date field or a string field?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More questions pending the answers to the above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 08:34:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296138#M22872</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-10-24T08:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296139#M22873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Dan!&lt;/P&gt;&lt;P&gt;This is the error that I'm getting:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Traceback (most recent call last):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; File "&amp;lt;string&amp;gt;", line 7, in &amp;lt;module&amp;gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 6569, in SelectLayerByAttribute&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; raise e&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 6566, in SelectLayerByAttribute&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in &amp;lt;lambda&amp;gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; return lambda *args: val(*gp_fixargs(args, True))&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;arcgisscripting.ExecuteError: ERROR 000358: Invalid expression&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Failed to execute (SelectLayerByAttribute).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Regarding your other questions, the date is in a field and is "date"&amp;nbsp;data type.&amp;nbsp; Yes, they are sequential dates from 2010 through today.&amp;nbsp; Hundreds per day.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Much appreciated, Shelby&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 13:08:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296139#M22873</guid>
      <dc:creator>ShelbyHines</dc:creator>
      <dc:date>2017-10-24T13:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296140#M22874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is likely the query you are using. the value Baker should be between quotes and the field name (if FC is stored in fgdb) would be without quotes. Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;arcpy.SelectLayerByAttribute_management ("crimelayer", "NEW_SELECTION", "NEIGHBORHOOD_ID = 'baker'")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Sorry no access to my computer at this time to verify a little more.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 13:18:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296140#M22874</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-10-24T13:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296141#M22875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Xander, this worked!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 17:58:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296141#M22875</guid>
      <dc:creator>ShelbyHines</dc:creator>
      <dc:date>2017-10-24T17:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296142#M22876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/people/Dan_Patterson"&gt;Dan_Patterson&lt;/A&gt;, I wonder if you know how to query for data from the last 365 days using a date field?&amp;nbsp; Thank you!&amp;nbsp; -Shelby&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 17:59:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296142#M22876</guid>
      <dc:creator>ShelbyHines</dc:creator>
      <dc:date>2017-10-24T17:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296143#M22877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime

n &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;now&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# ---- now &lt;/SPAN&gt;

t &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;timedelta&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;days&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;365&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# ---- used timedelta options &lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Now&amp;nbsp; {} \nThen {}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;n&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; n&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;t&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

Now&amp;nbsp; &lt;SPAN class="number token"&gt;2017&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;10&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;24&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;15&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;05&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;40.710201&lt;/SPAN&gt; 
Then &lt;SPAN class="number token"&gt;2016&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;10&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;24&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;15&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;05&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;40.710201&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# ---- see the help for working with arcpy time objects&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;/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;P&gt;Shelby.... To give you some ideas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:12:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296143#M22877</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select Layer by Attribute issues</title>
      <link>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296144#M22878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for this, will be testing this!&amp;nbsp; Was able to make it work with the help of a colleague:&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.SelectLayerByAttribute_management("crimelayer", "NEW_SELECTION", "REPORTED_DATE &amp;gt; timestamp '{0}'".format(str(year_ago)), None)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2017 19:38:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-layer-by-attribute-issues/m-p/296144#M22878</guid>
      <dc:creator>ShelbyHines</dc:creator>
      <dc:date>2017-10-24T19:38:26Z</dc:date>
    </item>
  </channel>
</rss>

