Hi all,
I am using ArcGIS 10.3 to update a field with a numeric value that represents the elapsed time since the data was captured. I can do this in a python script that I have attached to a model but I also want to be able to sometimes do it quickly from within ArcGIS desktop and I am stumped.
I have written a 3 step process:
1. Create an integer field then calculate the number of days since today (field name = ET):
In Field Calculator, ET =
(datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days
2. Create a conditional Statement for "Elapsed Time" field as follows:
Expression:
Reclass(!ET!)
def Reclass(ET):
if ( ET < 28):
return 1
elif ( ET>= 28 and ET < 91):
return 2
elif ( ET >= 91 and ET < 182):
return 3
elif ( ET >= 182 and ET < 365):
return 4
elif (ET >= 365):
return 5
3. Delete the ET field
I really just want to declare a variable in my conditional statement for ET which would save having to create then delete the ET field, but everything I have tried does not work, for example:
Expression:
Reclass(ET)
ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days
def Reclass(ET):
if ( ET < 28):
return 1
etc etc
I cannot find any examples of conditional statements that use a variable instead of a field value in the Field Calculator, so any help would be appreciated.