I have a DateTime field (ex: CreatedDate) and would like to only show the date with the label. How would I setup the label expression to do this using python?
Thanks in advance!
It seems there is no idea how to do that:
ArcGIS Idea - More and Better Examples of Label Expressions Using Python in ArcGIS
Hmmm...I tried for way too long to use python. Switched to VBScript parser and got what I wanted in a few minutes using FormatDateTime([field],2)...like what is shown in the idea above.
Thanks for the response!
You cannot use VBScript expressions if you are publishing to ArcGIS Server. I ran into this problem, and the key to understanding it is found in the first sentence of the third paragraph of the "Building label expressions" help topic:
"Field values are automatically cast to text strings."
Nonetheless, Python expressions are awkward for parsing strings because you can't use square brackets . For example, in the following expression:
the parser will look for a field called "0" and fail. Instead, you can use the following:
If a field is nullable, then you need to be prepared to handle a null value:
def FindLabel ([DATEFIELD]):
s = [DATEFIELD]
if s is None:
return s.split(" ").pop(0)
Of course, label performance is adversely affected by using a function, which in turn affects the return time on an ArcGIS Server map service.
[BTW, if you look at the examples, the most appropriate ones for parsing strings are in JScript, and that is probably the better route to take.]
This article ArcGIS Desktop explains date fields it may help. I was able to use below to pull the date.
def FindLabel ( [LASTUPDATE] ):
d = [LASTUPDATE]
a = d.split(" ")
Retrieving data ...