0

I am trying to use an expression to convert my date field to a simple %d,%b,%Y format. Right now it is in "%Y%m%d %H:%M:%S %z"

How do I do it properly using Python to do this in ArcGIS Pro?

Q&As from ArcMap have given me errors.

My labels are coming from my [Date] field.

Here's one example of a code I tried -

def FindLabel ( [Date]  ):
  return str(datetime.datetime.strptime([Date],"%Y/%m/%d %H:%M:%S %z").date()) 

and I got this error:

enter image description here

My labels look this :

enter image description here

I also tried this code:

from datetime import datetime  
def FindLabel ( [Date] ):  
  d = datetime.strptime([Date], '%Y/%m/%d %H:%M:%S %z')  
  return d.strftime('%d, %b %Y') 

enter image description here

4
  • 2
    What type is your ‘Date’ field? Text? Date? Jun 9, 2019 at 3:30
  • 1
    Please put error messages in your question body as text, not image. Images are not legible on all devices or free-text searchable.
    – Vince
    Jun 9, 2019 at 10:43
  • The field is 'Date' format
    – Brewkeeper
    Jun 10, 2019 at 17:47
  • The reason I put the errors as pictures is because the format they appear in the labeling expression window in ArcGIS Pro does not allow for them to be selected. If others have a suggestion for copying the errors with your cursor in the labeling expression area - please let me know.
    – Brewkeeper
    Jun 11, 2019 at 0:41

1 Answer 1

0

It might be a bit late but just in case you still have the same issue, the Python code I used was the following:

def FindLabel ( [Fecha]  ):
  return str(datetime.datetime.strptime([Fecha],"%d/%m/%Y").date()) 

You could change the field "Fecha" for "date", I used it that way cause my fields are in Spanish.

1
  • Thank you! If I ever need to solve this issue again I will give your solution a try
    – Brewkeeper
    Sep 10, 2020 at 23:24

Your Answer

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

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