How can I label the current date within a label expression?

664
2
Jump to solution
09-30-2019 06:10 AM
Tim-Woodfield
Occasional Contributor

Is there a way that I can label the current date from within a label expression without pulling from a field in the attribute table? I've been trying to use datetime.now() and datetime.today() but haven't been able to get those to work.

Thanks!

Tim

python‌ python label expression

0 Kudos
1 Solution

Accepted Solutions
WendyHarrison
Esri Contributor

Hi Timothy,

try:

def FindLabel ( 😞
     myVar = datetime.datetime.now()
     return myVar.strftime("%Y-%m-%d")

you can then format from there

def FindLabel ( 😞
     myVar = datetime.datetime.now()
     return myVar.strftime("%Y-%m-%d %H:%M:%S")

Thanks

Wendy

View solution in original post

2 Replies
WendyHarrison
Esri Contributor

Hi Timothy,

try:

def FindLabel ( 😞
     myVar = datetime.datetime.now()
     return myVar.strftime("%Y-%m-%d")

you can then format from there

def FindLabel ( 😞
     myVar = datetime.datetime.now()
     return myVar.strftime("%Y-%m-%d %H:%M:%S")

Thanks

Wendy

Tim-Woodfield
Occasional Contributor

This worked perfectly. I was able to incorporate my existing label expression right into it. 

Thanks for the help!

Tim

0 Kudos