<?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: Max Date - How to return unique IDs with Max Date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/max-date-how-to-return-unique-ids-with-max-date/m-p/283318#M21883</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sample of what it is returning?&amp;nbsp; there are dates in different formats, some are easier to deal with than others​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Apr 2015 22:37:08 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-04-22T22:37:08Z</dc:date>
    <item>
      <title>Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/max-date-how-to-return-unique-ids-with-max-date/m-p/283317#M21882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python Beginner - Using version 10.1 and not an SDE install I have an atribute table with firehydrant inspection data. I am trying to create a layer that will only show the records grouped by fire hydrant number and then only display the most recent inspection date. When I execute the following code it runs fine and does in fact create the layer but it doesn't select the Max Date. If I have a record for Hydrant 100 with two dates I only want the most recent date to be created within the new layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Appreciate any assistance on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace=r"Z:\GIS_Data\gdb\GIS_Test.gdb"

fc="COA_FH_Inspections"
cursor = arcpy.UpdateCursor(fc)
idlist = []
datelist = []

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; idlist.append(row.getValue('HydrID'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; datelist.append(row.getValue('TestDate'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

print idlist
print datelist

idunique = set(idlist)

#Make a layer from the feature class
arcpy.MakeFeatureLayer_management(fc, "lyr")

for i in idunique:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == idlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("lyr", "New_Selection", '"HydrID" = i')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("lyr", "subset_Selection",'"TestDate" = (Select Max("TestDate") from "lyr"')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again thank you - Terry&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:43:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/max-date-how-to-return-unique-ids-with-max-date/m-p/283317#M21882</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2021-12-11T13:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/max-date-how-to-return-unique-ids-with-max-date/m-p/283318#M21883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sample of what it is returning?&amp;nbsp; there are dates in different formats, some are easier to deal with than others​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2015 22:37:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/max-date-how-to-return-unique-ids-with-max-date/m-p/283318#M21883</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-04-22T22:37:08Z</dc:date>
    </item>
  </channel>
</rss>

