AnsweredAssumed Answered

calculate date field from string field

Question asked by louchios on Feb 26, 2014
Latest reply on Feb 27, 2014 by louchios
Hi I have the following python code where the field "datetime" is a string field and is different for each record. I want to convert the UTC time string to a date/time and then subtract 6 hours from it (CST).

It is telling me that "!datetime!" does not match the format of "%Y%m%d%H%M". The actual records within the field do match that format, but I think it is trying to use the string "!datetime!" rather than using the data within that field name.

I wonder if this is a quick formatting fix or I need to set up a cursor to go through each field? Thank you.

arcpy.CalculateField_management(pt, "DATE_CST", dt.strptime("!datetime!", "%Y%m%d%H%M")  - timedelta(hours=6), "PYTHON_9.3")