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

No apps configured. Please contact your administrator.

Developing a C# WebApi on Domain-Driven Design (DDD) in .Net6 using Clean Architecture

Total Page Visits: 1890 – Today Page Visits: 1

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

Creating your own SFTP application is now easier than ever. Using C# allows you to easily create a windows application to securely transfer your files. SFTP stands for SSH File Transfer Protocol. SSH is an encrypted and secure communication protocol

Loading Data from Multiple Tables into Data Grid using Entity Framework

Total Page Visits: 1890 – Today Page Visits: 1

Total Page Visits: 1890 - Today Page Visits: 1