Labeling with Dates

819
2
Jump to solution
01-21-2014 10:29 AM
NicholasGlover
New Contributor
Hello everyone,

I'm trying to label a feature class that has a date field in it. My problem is that I only want to get the mm/dd/yyyy, but when I try to label it through python it will bring up the time as well. I tried using an array on dateOff (the date field), but I still run into the issue of it grabbing part of the time. My question is, what do I need to do in my python script to only get the date information and not the time information to show up in my label.

Here is a sample of what I have done so far.
import os  def FindLabel ( [Cause_Of_Outage] , [Date_Off] ):   outageType = [Cause_Of_Outage]    dateOff = [Date_Off]    return 'Outage Type: ' + outageType + os.linesep +'Date Off: ' + dateOff[0:10]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaChisholm
Occasional Contributor III
Good day Nicholas,

As far as I know arcmap stores only date objects (without time). For this reason, I suspect the DateOff is a string field (which is why you're using the array on it).

If there is a space in between the year and the time, you can split your string using that space and take the first part (see below).

You may also want to use "/n" instead of os.linesep (at your discretion).
def FindLabel ( [Cause_Of_Outage] , [Date_Off] ):   outageType = [Cause_Of_Outage]    dateOff = [Date_Off].split(" ")[0]   return 'Outage Type: ' + outageType + '\nDate Off: ' + dateOff

Good luck, hope it works out!

View solution in original post

0 Kudos
2 Replies
JoshuaChisholm
Occasional Contributor III
Good day Nicholas,

As far as I know arcmap stores only date objects (without time). For this reason, I suspect the DateOff is a string field (which is why you're using the array on it).

If there is a space in between the year and the time, you can split your string using that space and take the first part (see below).

You may also want to use "/n" instead of os.linesep (at your discretion).
def FindLabel ( [Cause_Of_Outage] , [Date_Off] ):   outageType = [Cause_Of_Outage]    dateOff = [Date_Off].split(" ")[0]   return 'Outage Type: ' + outageType + '\nDate Off: ' + dateOff

Good luck, hope it works out!
0 Kudos
NicholasGlover
New Contributor
That seemed to do it Joshua! Thanks!
0 Kudos