I am trying to change the format of date field using ArcMap field calculator.
My data is currently in the format "%d/%m/%Y %h:%m:%s" (e.g. 5/05/2016 12:25:46 AM)
I want to change this to "%d/%m/%Y" (e.g. 5/05/2016). No time data.
I have been trying to use the following, but this does not work.
datetime.strptime( !DateField!, "%d/%m/%Y)
I have looked at several similar questions posted, but none seem to do this?
Python or VBScript is ok, using ArcGIS 10.3
Best Answer
The dates are stored as strings (to be precise, unicode) meaning that you need to construct a true Python
datetime
object and then manipulate it.If my date field
MyDate
is2017-08-09 08:51:32
, then I'd use this snippetstr(datetime.datetime.strptime(!MyDate!, "%Y-%m-%d %H:%M:%S").date())
to get2017-08-09
.If your date is
5/05/2016 12:25:46 AM
, you would need to usestr(datetime.datetime.strptime(s, "%d/%m/%Y %H:%M:%S %p").date())
to get5/05/2016