normalize date in python

568
2
11-03-2011 05:31 PM
WilliamIde
New Contributor II
My Management has directed that I normalize some of our tables. So I have to add some new fields.  OK done.  One of the new fields is Incident_date.  Well  existing is a field called report date.  About half of those fields are NULL.  There is also a field call create_date. So what I want to do is if the report date has data I want to use that, if not then I want to use create_date.

So I fired up calculate field. Selected the table and selected Incident as the field.  Clicked on Python, and entered:

def CalIncident(Repdat, CrteDat):
  if ( Repdat == NULL) :
    return CrtDat
  else
    return Repdat



Other window
ReportDate =
CalIncident(!ReportDate!, !CreateDate!)

I don't think it understands NULL in this context.  Any idea what I should use?

Thanks
Tags (2)
0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor
Try using None instead of NULL in your python code.

See this python documentation on the null object: http://docs.python.org/release/2.5.2/lib/bltin-null-object.html
0 Kudos
benk
by
New Contributor
First you forgot : behind else, maybe this is your error.

If this isn't the problem I think it could work if you just test if Repdat is true:
if (Repdat): return CrtDat
else: return Repdat

Or you can try the other way:
if len(Repdat)>0: return Repdat
else: return CrtDat
0 Kudos