1

I have a small block of code where I concatenate two date fields and use field calculator to calculate a the values of a third field. My date fields are ORIGDTDATE and ORIGDTTIME.

How can I change the block of code that is below to concatenate the fields if the value for the row in emergency_overdue is NULL?

import arcpy 
calcExpression = "!ORIGDTDATE!+\" \"+ !ORIGDTTIME!" 

arcpy.CalculateField_management(self.line_ticket_feature_class,"emergency_overdue",calcExpression,"PYTHON_9.3")

arcpy.CalculateField_management(self.poly_ticket_feature_class,"emergency_overdue",calcExpression,"PYTHON_9.3")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 28, 2016 at 18:26
1
  • Select by attribute, apply 1st, switch selection, apply second. I would replace it with da. Update Cursor, works much faster Commented Nov 28, 2016 at 18:34

1 Answer 1

1

You can create an update cursor with a where clause for only rows where emergency_overdue is null. The code below is a straight concatenation of the date and time fields, you may want to use a separator like "ORIGDTDATE" + ":" + "ORIGDTTIME".

with arcpy.da.UpdateCursor(self.line_ticket_feature_class, ["ORIGDTDATE", "ORIGDTTIME", "emergency_overdue"], "emergency_overdue IS NULL") as ucur:
 for row in ucur:
 row[2] = row[0] + row[1]
 ucur.updateRow(row)
answered Nov 28, 2016 at 19:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.