Convert Time Field

1193
3
02-07-2014 03:10 AM
AdamBeard
New Contributor II
This tool seems very strait forward but is causing issues when put into python. Works fine in ArcMap and I get the expected results.

My Input Time Field(Text Field) looks like:
2014-02-01 02:11 AM

inputTimeField = "Incident_Date___Time"
inputTimeFormat = "1033;yyyy-MM-dd HH:mm tt"
outputDateField = "IncDateTime"                      
arcpy.ConvertTimeField_management("myFGDB",inputTimeField,inputTimeFormat,outputDateField)
arcpy.DeleteField_management(blot,"DateTime")


After the tool is run the IncDateTime Field comes back as:
1/1/2001

Am I missing something here?
Tags (2)
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Adam,

A good trick to get the syntax correct is to run the tool in ArcMap, then open the Results window (Geoprocessing menu > Results).  Right-click on the completed tool > Copy As Python Snippet.  You can then paste this into your script.
David_JAnderson
New Contributor III
I would suggest looking at the python datetime module.  It will do anything you can think of for manipulating date and time values.
0 Kudos
TimothyElliott
New Contributor III
Just a word of warning In a file geodatabase the date and times are all stored as unicode strings, and you need to specify that when manipulating them with Python.
  time_value.encode('utf-8'), "%d/%m/%Y %I:%M:%S %p") 
0 Kudos