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?
Solved! Go to Solution.
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 testing
def 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.
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 testing
def 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.