Converting date field using ArcMap

arcgis-desktoparcpydatefield-calculator

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?

Best Answer

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

enter image description here

See: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

to understand the '%d-%b-%Y' etc.