awise

Field Calculator - Dates using Python

Discussion created by awise on Feb 21, 2011
Latest reply on Feb 22, 2011 by awise
Hi All,

I am trying to parse a string field into date field but having some issues with the ArcGIS field calculator.

Strings are in the format of:
idr02_20110203_0000_256.png
being
idr02_YYYYMMDD_HHMM_256.png

I have tested my string parsing in the python console but for having some difficulty getting ArcGIS field calculator to accept it in the following format:

CodeBlock=
------
def MyFunction(nameInput):
  rasterParts = nameInput.split("_")
  newDate = datetime(int(rasterParts[1][0:4]), int(rasterParts[1][4:6]),int(rasterParts[1][6:8]),int(rasterParts[2][0:2]),int(rasterParts[2][2:4]) )
  return newDate
-----
Expression=
---
MyFunction( !Name! )
--

It keeps coming back with:

Messages
ERROR 000539: Error running expression: MyFunction("idr02_20110203_0000_256.png")  <type 'exceptions.TypeError'>: 'module' object is not callable

Can anybody spot the error or have any alternative methods for parsing out the date?

Thanks
Andrew

Outcomes