1

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

1

2 Answers 2

3

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 is 2017-08-09 08:51:32, then I'd use this snippet

str(datetime.datetime.strptime(!MyDate!, "%Y-%m-%d %H:%M:%S").date()) to get 2017-08-09.

If your date is 5/05/2016 12:25:46 AM, you would need to use

str(datetime.datetime.strptime(s, "%d/%m/%Y %H:%M:%S %p").date()) to get 5/05/2016

2

No need for python, just use the Convert Time Field tool!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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