Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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])


share|improve this question
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

Your Answer


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.