<?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: Delete features based on Date using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466424#M36458</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Xander. That worked perfectly!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jan 2020 19:11:38 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-01-09T19:11:38Z</dc:date>
    <item>
      <title>Delete features based on Date using Python</title>
      <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466420#M36454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;We have some feature classes stored in a feature dataset in ArcSDE . I want to delete the features which are older than 10 years from the feature classes using a python script.&lt;/P&gt;&lt;P&gt;Every feature class has an attribute field "LAST EDITED ON". The sample value is in format "10/14/2014 1:31:52 AM".&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The features which are older than 10 years should be deleted from every feature class on daily basis (If there are any).&lt;/P&gt;&lt;P&gt;We are using ArcGIS version 10.1&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created following expression which selects the features for deletion.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expression = long(float((arcpy.CalculateValue_management(time.mktime((datetime.datetime.now()+relativedelta(years=-10)).timetuple())))[0])) - long(float((arcpy.CalculateValue_management(time.mktime(time.strptime(!LAST_EDITED_ON!, "%x %X"))))[0])) &amp;gt; 0&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expression runs fine on Python window but gives an error while running as a tool.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SyntaxError: invalid syntax (DeleteFeatureScript_Latest.py, line 18)&lt;/P&gt;&lt;P&gt;Failed to execute (Script).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 18 is the expression seen above.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest how to solve this problem.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 08:45:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466420#M36454</guid>
      <dc:creator>nageshnangi1</dc:creator>
      <dc:date>2014-11-06T08:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Delete features based on Date using Python</title>
      <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466421#M36455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suppose you are using the "Delete Features (Data Management)" tool to delete the features and the expression you showed is the one specified in that tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use python the syntax can be different for the expression than the one you use in the dialog manually. In this case you specify "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;!LAST_EDITED_ON!" as the field. This produces an invalid syntax in Python. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;If you look at the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000036000000"&gt;Help&lt;/A&gt;, and scroll down to the second code sample, you see that the field is specified differently. They also use the &lt;EM&gt;arcpy.AddFieldDelimiters(FeatureClassOrTable, FieldName)&lt;/EM&gt;, to make sure that the field is addressed correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Since you didn't specify the rest of the script it is impossible to verify if the error is indeed caused by this. You could try changing the code to:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_1415279511700287" jivemacro_uid="_1415279511700287"&gt;
&lt;P&gt;fc = r"Path to your featureclass or table"&lt;/P&gt;
&lt;P&gt;fld = "LAST_EDITED_ON"&lt;/P&gt;
&lt;P&gt;fld_ok = arcpy.AddFieldDelimiters(fc, fld)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;expression = long(float((arcpy.CalculateValue_management(time.mktime((datetime.datetime.now()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + relativedelta(years=-10)).timetuple())))[0])) - long(float((&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateValue_management(time.mktime(time.strptime(fld_ok, "%x %X"))))[0])) &amp;gt; 0&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if this will work though...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 13:12:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466421#M36455</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-11-06T13:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Delete features based on Date using Python</title>
      <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466422#M36456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xander,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My goal is to delete features in based on a date range in a FGDB feature class. I ran into problem when trying to specify the query for the dates. Here is what I have so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;fc = r 'Feature Class'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(fc, "LASTUPDATE") as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if row[0] ==&amp;nbsp; Between 1/01/2019 0:00:00 PM AND &lt;SPAN&gt;1/01/2020 0:00:00 PM&lt;/SPAN&gt;:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cursor.deleteRow()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What would be the correct format for deleting all records&amp;nbsp;within the range? Any help is greatly appreciated. Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2020 18:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466422#M36456</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-01-09T18:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Delete features based on Date using Python</title>
      <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466423#M36457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/migrated-users/342090" target="_blank"&gt;Collin Horace&lt;/A&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You probably have to change the condition like this:&lt;/P&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; arcpy
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime

fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'Feature Class'&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"LASTUPDATE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt;  datetime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;year&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2019&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; month&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; day&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;year&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2020&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; month&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; day&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;deleteRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&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;/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;&lt;/P&gt;&lt;P&gt;You can also create a selection using the where clause and use the&amp;nbsp;arcpy.DeleteFeatures_management() tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test on a copy of you data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:41:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466423#M36457</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T20:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Delete features based on Date using Python</title>
      <link>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466424#M36458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Xander. That worked perfectly!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2020 19:11:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-features-based-on-date-using-python/m-p/466424#M36458</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-01-09T19:11:38Z</dc:date>
    </item>
  </channel>
</rss>

