ArcMap 10.4 – Using python function in field calculator to update date values from another column

In ArcMap 10.4 you can use a python function to update the date type value of one column from another column using field calculator. Below a code snippet on how to achieve this provided that the date value is not just time.

Step 1 – Select the layer that you want to make update to. Right click on the layer and select open attribute table from the pop up menu.

 

 

 

 

 

 

 

Step 2 – Highlight the rows of data you want to make changes to and then right click on the header of the column. Select Field Calculator from the pop up menu.

 

 

 

Step 3 – In the Field Calculator dialogue box select  “Show Codeblock”. Add the python function in the section where it says ‘Pre-Logic Script Code’:

from datetime import datetime

def validate(date_text):
try:
if date_text != datetime.strptime(date_text, "%m/%d/%Y").strftime('%H:%M:%S'):
return date_text
except ValueError:
return None

In the section below add a call to the function:

validate(!Date!)

Arcmap attribute table
Open your layers attribute table
Arcmap Field Calculator Python Function
Add your custom python function in Field Calculator
ArcMap Field Calculator Python Function
Add your custom python function here

Leave a Reply



How to code your own sFTP File Uploader Windows application using C# and SSH

Total Page Visits: 359 – Today Page Visits: 1

Loading Data from Multiple Tables into Data Grid using Entity Framework

Total Page Visits: 359 – Today Page Visits: 1

XLS to DBF File Conversion using ExcelDataReader

Total Page Visits: 359 – Today Page Visits: 1

Total Page Visits: 359 - Today Page Visits: 1