Stand-Alone Python Script - Date Field Modification

207
3
06-20-2019 07:36 AM
ModernElectric
Occasional Contributor III

I've been doing alot of research on how to accomplish a specific task and from what I can tell, it seems to frustrate many people and I am really starting to agree.

I am developing a series of Python Scripts (converting from data models) to import reading data and dates to prepare for our GIS database. One of the tasks in the series is dealing with the date field(s). The raw data for the READING_DATE field (Date Type) comes in as m-d-y-h-m-s (Ex. 1/1/2019 12:10:00). I need to go from this format to a format of m-y (Ex. Jan-2019). I am not sure exactly how to do this. In my data model, I use the Convert Time Field tool. However, when running this tool on over 500,000 records it takes a LONG time. 

I am thinking about using the Arcpy Update Cursor but still new to using this feature. Would like some help in how to set-up the script code and exactly what field type(s) I need to accomplish this.  

Thank You

0 Kudos
3 Replies
ModernElectric
Occasional Contributor III

I have done this so far:

Taken the Date field (READING_DATE) and copied over to READING_DATE_TEXT (Text Field). I am trying to use Calculate Field tool to convert, but keep getting an error:

Here is the READING_DATE_TEXT Field I am trying to convert from:

Thank You

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It looks like you are using ArcMap, is that correct?  I ask because how dates are handled by cursors and field calculator differs between ArcMap and ArcGIS Pro.

0 Kudos
ModernElectric
Occasional Contributor III

I guess we can disregard this. After spending hours trying to figure out what was going wrong, I figured it out. There were some entries from the raw data from the Oracle database export that was format differently, so when the script got to them, it crashed. Some of those rows had a format of ONLY m/d/y and missing the time. I had to add another tool to select and delete those rows so the script worked perfectly afterwards.