I want to label point features with a date field. The labels show long date and time. I do not want to show the time, just the date. Is there a way to format the label to show only the date?
You can change date label format in the label expression.
Here are the VBScript Date functions.
Likewise, search for Python date functions.
Let's say I take a date field which has values like: 7/23/2015 7:00:00 AM. When I use the VB function TIMEVALUE to label the field it returns 7:00:00 AM.
If I want it to return 7 AM, how do I format the VB line?
You can find a list of time format tags here: ArcGIS Help 10.1. Essentially, you would use the tag, format= "h tt".
You can use a python function for the label expression to change your date format. Click on the Expression button on the Label properties then:
Python function for the label expression:
from datetime import datetime
def FindLabel ( [TestDate] ):
d = datetime.strptime([TestDate], '%d/%m/%Y %H:%M:%S %p')
return d.strftime('%d, %b %Y')
A list of format strings is available here:
Hope this helps.
Unfortunately, I have some dates with times, some without. None of these solutions work without writing a much more complex script to identify the format. This is much too complicated. Why can't it recognize what format, and allow us the option to display it in whatever format we choose?
I have the same question regarding displaying only the month and day of the date.
This is a snip of the date field in ArcMap
I've tried this code:
from datetime import datetime def FindLabel ( [StartDate] ): d = datetime.strptime([StartDate], '%m/%d/%Y %I:%M:%S %p') return d.strftime('%d %m')
This is the error I am getting when I verify the expression. I read this so I know that the zero-padded date is not an issue..
Any insight on why the error is showing?
Retrieving data ...