Good morning,
I am working on arcmap and I would like to set up a script that would allow me to add years.
I have a data arbres_ev which includes as field: date_diag (format_date), periodicity (integer) ,maj_previsional(format_date). the objective is to fill in the field maj_previsional whose value would correspond to: maj_previsional + periodicity therefore if periodicity=1 add one year...
I tested this script:
fields = ['date_diag','periodicity','maj_previsional']
#print(fields)
today = datetime.datetime(today.year, today.month, today.day)
with arcpy.da.UpdateCursor(inFeatures, fields) as cursor:
for the cursor line:
#print(str(row[1])
if ((str(row[0]) != ') and (str(row[1]) =='1'):
row[2] = arcpy.time.ParseDateTimeString(str(row[0])) + datetime.timedelta(days=365)
if ((str(row[0]) != ') and (str(row[1]) =='2'):
row[2] = arcpy.time.ParseDateTimeString(str(row[0])) + datetime.timedelta(days=730)
if ((str(row[0]) != ') and (str(row[1]) =='3'):
row[2] = arcpy.time.ParseDateTimeString(str(row[0])) + datetime.timedelta(days=1095)
if ((str(row[0]) != ') and (str(row[1]) ='4'):
row[2] = arcpy.time.ParseDateTimeString(str(row[0])) + datetime.timedelta(days=1460)
if ((str(row[0]) != ') and (str(row[1]) =='5'):
row[2] = arcpy.time.ParseDateTimeString(str(row[0])) + datetime.timedelta(days=1825)
cursor.updateRow(line)
print("Second part complete!")
So for a year it works but as soon as I spend the two years it doesn’t work.
can I use this function? If not, what function should I take?
thanking you for your help