3

Given a dataset with a date field, how would I select the row with the most recent date using Python or ArcPy?

asked Nov 5, 2014 at 14:38
1
  • 2
    Here are some approaches that were noted in another post. Note the sections where the OP is wanting the most recent fire: gis.stackexchange.com/questions/95378/… Commented Nov 5, 2014 at 14:42

2 Answers 2

5

Building from evv_gis comment:

  1. Use search cursor to iterate through layer and assign date values to list
  2. Use max method on list to get the newest value
  3. Make feature layer of layer
  4. Use the select layer by attribute method on feature layer with value from step 2
answered Nov 5, 2014 at 15:11
2

In the spirit of completeness here is my final script, minus making a feature layer, which I will add in production.

listdates = []
cursor = arcpy.da.SearchCursor(layername, "Date_Mod")
for row in cursor:
 listdates.append(row)
maxdate = max(listdates)
maxdatestr = str(maxdate)
datestr = maxdatestr[19:31]
arcpy.SelectLayerByAttribute_management(layername, "NEW_SELECTION", "Date_Mod = date '" + datestr + " 00:00:00'")

Thanks to everyone that answered and commented.

answered Nov 5, 2014 at 16:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.