I need to convert a text field "Year1" into a date filed (Year1) with just the year.
Field Year is a text field, with just a year date, "2015" and field Year1 is a date field.
from datetime import datetime
from datetime import time
import datetime as dt
from time import gmtime, strftime
def calcYear():
fc = "Lyr"
#testdate = '04/25/2015'
with arcpy.da.UpdateCursor(fc,['Year','Year1']) as cursor:
for row in cursor:
if row[0] not in (""," ",None):
d1 = datetime.strptime(datetime.strftime(row[0], "%Y"), "%Y")
row[1] = d1.year
cursor.updateRow(row)
I get the following error. I was thinking that line 11 was converting the text into a day(year).
ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 11, in calcYear
TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'int'
Failed to execute (Calculate Field