Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a field called Abandoned Year (short integer data type) that I am trying to populate with a four digit year from a column called Decommission Date (Date data type). I have done this in the past using the DatePart( ) VB function but how do I accomplish this same task in a Python field calculation?

Here is the code written in VB:

AbandonedYear = DatePart ("YYYY", [DecommissionDate])

Thanks

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Try this:

AbandonedYear = datetime.datetime.strptime( !DecommissionDate! , '%m/%d/%Y %I:%M:%S %p').year

You may need to change the format, if so a reference for those format strings is found here: Python Documentation

share|improve this answer
    
Thanks! I got this to work, datetime.datetime.strptime(!DecommissionDate!, '%m/%d/%Y').year –  user19300 Jun 20 '13 at 14:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.