# Change status type of a feature based on the most recent date input between multiple attributes?

95
1
07-20-2020 11:48 AM
by
MVP

I need to automate the process of changing a feature's status attribute based on the most recent date that's input between three of its attributes. Any ideas?

1 Solution

Accepted Solutions
MVP Regular Contributor

If I understand your question correctly, you want to change the status field based on the most recent date in 3 date fields.

You can use an UpdateCursor or the FieldCalculator and a modified version of:

``from datetime import datetime # to make dates for testingdef status(date1, date2, date3):    stat = ['Status 1', 'Status 2', 'Status 3']    dates = [date1, date2, date3]     return stat[dates.index(max(dates))]print(status(datetime(2020, 7, 12, 10, 10), # 3 fields with dates             datetime(2018, 6, 12, 10, 10),             datetime(2017, 8, 12, 10, 10)))‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``

If it is possible that two date fields could have the same maximum date, the first date in the list that matches would be returned.  So the order of the status and date fields would need to be in order of most to least important.

``from datetime import datetime # to make dates for testingdef status(date1, date2, date3):    stat = ['Status 1', 'Status 2', 'Status 3']    dates = [date1, date2, date3]     return stat[dates.index(max(dates))]print(status(datetime(2020, 7, 12, 10, 10), # 3 fields with dates             datetime(2018, 6, 12, 10, 10),             datetime(2017, 8, 12, 10, 10)))‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``