arcpy.CalculateField_management(pt, "DATE_CST", dt.strptime("!datetime!", "%Y%m%d%H%M") - timedelta(hours=6), "PYTHON_9.3")
Solved! Go to Solution.
arcpy.ConvertTimeField_management(pt,"datetime","yyyyMMddHHmmss, yyyy/MM/dd HH:mm:ss", "DATETIME_Converted") arcpy.AddField_management(pt, "DATETIME_CST", "DATE") arcpy.CalculateField_management(pt, "DATETIME_CST", "DateAdd(\"h\",-6,[DATETIME_Converted])", "VB", "")
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")
arcpy.ConvertTimeField_management(pt,"datetime","yyyyMMddHHmmss, yyyy/MM/dd HH:mm:ss", "DATETIME_Converted") arcpy.AddField_management(pt, "DATETIME_CST", "DATE") arcpy.CalculateField_management(pt, "DATETIME_CST", "DateAdd(\"h\",-6,[DATETIME_Converted])", "VB", "")