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

  • 2
    What type is your ‘Date’ field? Text? Date? – Son of a Beach Jun 9 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 at 10:43
  • The field is 'Date' format – Brad-Nissen Jun 10 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. – Brad-Nissen Jun 11 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.