I need to convert the date field in the feature class. The original date format is 15-Jan-2012, 27-Apr-2012, likewise.
How can I convert it into MM/dd/yyyy format?
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 communityI need to convert the date field in the feature class. The original date format is 15-Jan-2012, 27-Apr-2012, likewise.
How can I convert it into MM/dd/yyyy format?
Use Field Calculator with Python parser. I calculate a new field but you can overwrite your original field if you want to.
def convdate(f):
from datetime import datetime
dobj = datetime.strptime(f, '%d-%b-%Y') #Create a datetime object
newdate = datetime.strftime(dobj, '%m/%d/%Y') #Convert back to string in the format you ask for
return newdate
convdate( !datefield!) #Replace datefield with the name of your existing field
See: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
to understand the '%d-%b-%Y'
etc.