I work with ArcGIS Pro 3.1. I have a GDB table with two date fields. I would like calculate with Python code the difference between two date in days. But the result is not correct if the months are different (For example: ID 3 and 4).
arcpy.management.AddField(tabl, "day","TEXT")
exc= "computeDiff(!e_date!, !s_date!)"
codeblock="""
def computeDiff(start,end):
FMT = "%Y. %M. %d."
tday = datetime.datetime.strptime(start, FMT) - datetime.datetime.strptime(end,FMT)
return str(tday)"""
arcpy.management.CalculateField(tabl, "day", exc, "PYTHON_9.3",codeblock)