I've got a script that does a number of Date/Time conversions using arcpy.ConvertTimeField_Management. A common issue that I need to handle is when the field is empty and an execute error is raised:

arcgisscripting.ExecuteError: ERROR 000192: Invalid value for Time Format = 'yyyyMMddHHmmss' - was not able to successfully convert any row's time field value

This error occurs when I use the try/except below; I'd like the script to ignore this error and continue. Any ideas?

try: results = arcpy.ConvertTimeField_management(SA_TEN_GOV_els, "START_DATE", "yyyyMMddHHmmss", "START_DAT", "DATE", "'Not Used'") except: print results.getMessages() pass

  • 1
    Create a layer that contains non-empty rows and perform the calculation on that. – Michael Stimson Dec 17 '14 at 4:08
  • 1
    Negative, unless you switch to update cursor and split input. – FelixIP Dec 17 '14 at 4:58
  • I agree with @FelixIP, the ConvertTimeField command operates at a featureClass level, so it either works or it fails. If you need to ignore errors but keep the good values, you'll need to handle it yourself in a cursor. Or, pre-select the features as Michael and Emil suggested. – Stephen Lead Dec 19 '14 at 3:55

As Michael suggested, first creating a layer file of populated rows should do the trick.

Before your code, create a variable with the proper SQL query, and then create your layer file. Execute your time conversion on your layer file.


arcpy.MakeFeatureLayer_management (SA_TEN_GOV_els, "lyr", sql)
arcpy.ConvertTimeField_management("lyr", "START_DATE", "yyyyMMddHHmmss", "START_DAT", "DATE", "'Not Used'")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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