<?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 by recent date - specific date field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1550600#M89336</link>
    <description>&lt;P&gt;I don't think using the &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/whats-new-from-the-geodatabase-team-in-arcgis-pro-3-2/#New-Date-and-Time-Field-Data-Types" target="_self"&gt;DATE_ONLY&lt;/A&gt; field vs the "older" DATE_TIME field would matter.&amp;nbsp; The DATE_ONLY field would return a Month-Date-Year field and not have the time obviously.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Oct 2024 19:48:10 GMT</pubDate>
    <dc:creator>Robert_LeClair</dc:creator>
    <dc:date>2024-10-21T19:48:10Z</dc:date>
    <item>
      <title>Select by recent date - specific date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1548828#M89175</link>
      <description>&lt;P&gt;There is nothing more frustrating in working with a GDB FC/Table then dealing with a date field.&lt;/P&gt;&lt;P&gt;I am simply trying to run a Select Layer by Attribute tool via Python to select the most recent date in a file GDB feature class in a date field type. All my research have failed in being successful.&lt;/P&gt;&lt;P&gt;I have a Make Feature Layer and Select Layer by Attribute tool.&lt;/P&gt;&lt;P&gt;The recent expression:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.SelectLayerByAttribute(SURVEY123_EWO_REGULAR_HOURS_FL, "NEW_SELECTION", "date_ewo = (SELECT MAX(date_ewo) FROM SURVEY123_EWO_REGULAR_HOURS)")&lt;/LI-CODE&gt;&lt;P&gt;Presently, I have (3) entries in the Feature Layer and still the selection exports all (3) entries versus just (1). In the future, this FC is going to grow and I need to be able to select the most recent entry each time I run the tool.&lt;/P&gt;&lt;P&gt;Appreciate any help&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 20:05:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1548828#M89175</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2024-10-15T20:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select by recent date - specific date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1549769#M89252</link>
      <description>&lt;P data-unlink="true"&gt;Caveat - I am not a Python person but I found a Python script written via this &lt;A href="https://gis.stackexchange.com/questions/121031/select-the-most-recent-date-from-a-table-using-python-arcpy" target="_self"&gt;page&lt;/A&gt;&amp;nbsp;that seems to accomplish the task at hand:&lt;/P&gt;
&lt;PRE class="lang-py s-code-block"&gt;&lt;CODE class="hljs language-python" data-highlighted="yes"&gt;listdates = []
cursor = arcpy.da.SearchCursor(layername, &lt;SPAN class="hljs-string"&gt;"Date_Mod"&lt;/SPAN&gt;)

&lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; cursor:
    listdates.append(row)

maxdate = &lt;SPAN class="hljs-built_in"&gt;max&lt;/SPAN&gt;(listdates)
maxdatestr = &lt;SPAN class="hljs-built_in"&gt;str&lt;/SPAN&gt;(maxdate)
datestr = maxdatestr[&lt;SPAN class="hljs-number"&gt;19&lt;/SPAN&gt;:&lt;SPAN class="hljs-number"&gt;31&lt;/SPAN&gt;]

arcpy.SelectLayerByAttribute_management(layername, &lt;SPAN class="hljs-string"&gt;"NEW_SELECTION"&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;"Date_Mod = date '"&lt;/SPAN&gt; + datestr + &lt;SPAN class="hljs-string"&gt;" 00:00:00'"&lt;/SPAN&gt;)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 22:35:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1549769#M89252</guid>
      <dc:creator>Robert_LeClair</dc:creator>
      <dc:date>2024-10-17T22:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Select by recent date - specific date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1550519#M89327</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2538"&gt;@Robert_LeClair&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the information. I've tried the script you sent, and also found another script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(feature_class, [date_field]) as cursor:
    max_date = None
    for row in cursor:
        date_value = row[0]
        if max_date is None or date_value &amp;gt; max_date:
            max_date = date_value

print("Maximum date: ", max_date)

arcpy.SelectLayerByAttribute_management(feature_class, "NEW_SELECTION", date_value)

arcpy.conversion.ExportFeatures(feature_class, layername_export)
print("EXPORT")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of the scripts exports all of the rows from the feature class to a new feature class. The goal is to only select and export the newest date regardless if there is 1 feature or 200 features in the feature class. As time progresses, this feature class is going to grow overtime and the next script(s) will rely on having (1) record and it needs to be the most recent record.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question, does that need to be a DATE_ONLY field type or is it okay to be a DATE-TIME&amp;nbsp; field type? Not sure if this makes a difference.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 16:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1550519#M89327</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2024-10-21T16:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select by recent date - specific date field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1550600#M89336</link>
      <description>&lt;P&gt;I don't think using the &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/whats-new-from-the-geodatabase-team-in-arcgis-pro-3-2/#New-Date-and-Time-Field-Data-Types" target="_self"&gt;DATE_ONLY&lt;/A&gt; field vs the "older" DATE_TIME field would matter.&amp;nbsp; The DATE_ONLY field would return a Month-Date-Year field and not have the time obviously.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 19:48:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-by-recent-date-specific-date-field/m-p/1550600#M89336</guid>
      <dc:creator>Robert_LeClair</dc:creator>
      <dc:date>2024-10-21T19:48:10Z</dc:date>
    </item>
  </channel>
</rss>

