Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a Date field in an ArcGIS file geodatabase feature class called "DateTemp1." I created a new text field called "DateTemp2" and want to calculate that based on the DateTemp1 field, but I am getting a unicode error.
TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'unicode'
arcpy.CalculateField_management("all_reports.gdb/lsr_reports1", "DateTemp2", "datetime.datetime.strftime(!DateTemp1!, '%Y%m%d')", "PYTHON_9.3", "")
–
–
I looked into using the Convert Time Field tool as the poster suggested and it worked.
inTable = "all_reports.gdb/lsr_reports1"
inputTimeField = "DateTemp1"
inputTimeFormat ="dd/MM/yyyy HH:mm:ss;AM;PM"
outputDateField = "DateTemp2"
arcpy.ConvertTimeField_management(inTable, inputTimeField, inputTimeFormat, outputDateField)
Try using "datetime.datetime.strptime( !DateTemp1! , '%d/%m/%Y').strftime('%Y%m%d')"
as your expression:
arcpy.CalculateField_management("all_reports.gdb/lsr_reports1", "DateTemp2", "datetime.datetime.strptime( !DateTemp1! , '%d/%m/%Y').strftime('%Y%m%d')", "PYTHON_9.3", "")
NOTE you will need to change the '%d/%m/%Y'
from in strptime( !DateTemp1! , '%d/%m/%Y')
to match the current format of your existing date field
–
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.