[GIS] Changing date format for labels in ArcGis Pro with label expression

arcgis-prodatetimelabelingpython-parser

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

Best Answer

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.

Related Question