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!)"
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)

enter image description here

1 Answer 1


The format code for "month" is a lower-case %m. You're currently specifying "year minute day".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.