Geographic Information Systems Asked by user10680652 on April 15, 2021
I tried to copy a field with dates that had type ‘TEXT’ to a new column of type ‘DATE’ because it is not possible to change the initial type of the original field.
arcpy.CalculateField_management(r'C:UsersUSERDesktopDeuv.shp','DC_DATE','DC_DATE1')
The initial field has all rows with data but it gives this error:
‘Empty value for Objectid = 0’
And it can’t copy anything to the other field.
You need to convert your text into a datetime format. So using the datetime.strptime method, you have to decipher what your text date looks like, and convert that into a datetime format.
Using the UpdateCursor, you can search for your string date, convert that into a datetime object, then update the new field with the correct date object.
Please see link for more information on the DateTime python module.
For example:
import datetime
string_date = "23/11/18 12:30"
string_date_into_datetime = datetime.datetime.strptime(string_date, "%d/%m/%y %H:%M")
print string_date_into_datetime
Answered by MacroZED on April 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP