How do I label date attributes in a different format?

937
2
Jump to solution
01-21-2020 04:18 PM
DaleArnold
New Contributor

I have an attribute I would like to label on my map that has dates in mm/dd/yyyy format.   When I label the map, it displays in that format (as one would expect).   I want to draw the labels in a different format, specifically mmm yyyy or mmm yy format.   I can get a dynamic text box to update with the date on the map, but I want a map to populate with project dates over the features.   Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Regular Contributor

What are you working with - Desktop 10.x, Pro, AGOL ?  With Desktop for example, the label manager allows for creating an expression.  Python  code would be something like (note: advanced checked):

from datetime import datetime

def FindLabel ( [EditDate] ):
  ds = datetime.strptime([EditDate], '%m/%d/%Y %H:%M:%S %p')
  return ds.strftime("%B %Y")

Label Manager

View solution in original post

2 Replies
RandyBurton
MVP Regular Contributor

What are you working with - Desktop 10.x, Pro, AGOL ?  With Desktop for example, the label manager allows for creating an expression.  Python  code would be something like (note: advanced checked):

from datetime import datetime

def FindLabel ( [EditDate] ):
  ds = datetime.strptime([EditDate], '%m/%d/%Y %H:%M:%S %p')
  return ds.strftime("%B %Y")

Label Manager

DaleArnold
New Contributor

Randy,

Thank you SO much!   (FYI I am using ArcGIS Pro.)   This was pretty much exactly what I needed!   I only needed to edit two things, but this was the final leg I needed to get it working correctly!  

In case you were wondering, I had two fields I wanted displayed (a project name and start date) so I added "[proj_name] + '\n' +" before the ds.strftime (%b %y) expression.  And my time attribute apparently ONLY has mm/dd/yyyy so it errored-out until I removed the timegroup and timezone from the strptime function.    (Also as above, I only wanted the mmm and yy, so I made the minor change to the strftime function. 

This was really wracking my brain.   Thanks again!

Dale

0 Kudos