Why won't my Date Variable work?

2201
7
Jump to solution
11-07-2017 12:27 AM
LindsayRaabe_FPCWA
Occasional Contributor III

I seem to be having  issues getting a String variable to work. I am attempting to get a Date (formatted as YYYYMMDD) in a String Variable which then gets used as a part of an export filename. I was getting a "1" output instead of the Date originally (and other errors) but now I am managing to get the date but also keep getting errors about incorrect naming. Can anyone tell me what is wrong? The original demo tool I used to figure this out so far (provided here) has the same issue!

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Curtis is suggestion that you use the expression that he posted above in your field calculator expression rather than hardcoding the % symbols. 

I use python 3.5 so I am not sure what he is expecting as output, but here is what I get

time.strftime(u"zzz{0}d{0}m{0}Y".format(chr(37)))

'zzz12112017'   # which appears to be day, month and year of today

View solution in original post

7 Replies
curtvprice
MVP Esteemed Contributor

I cannot reproduce your issue @ 10.5.1.  But: percent signs are significant to ModelBuilder as they delimit ModelBuilder variables. If you have a variable "d" or "m" in your model I could see that breaking things, or maybe you are using a different version of ArcGIS where the parser isn't as smart.

You may be able to avoid this issue by hiding percent signs in your time code string like this using the Python chr() function and string formatting:

time.strftime("zzz{0}d{0}m{0}Y".format(chr(37))‍‍‍‍‍)

Update: This is a Calculate Value expression you can use instead of what you're using, which hides the "%" from Model Builder. The strftime function will see this: "zzz%d%m%Y" (the expression chr(37) is equal to "%", which I then substituted in to the expression using the .format() method. 

LindsayRaabe_FPCWA
Occasional Contributor III

Here's a copy of the tool I've been testing this in. Not quite sure how to use the script you provided (pretty much a Python novice). We too are using 10.5.1 and there is only the one variable in the tool. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
DanPatterson_Retired
MVP Emeritus

Curtis is suggestion that you use the expression that he posted above in your field calculator expression rather than hardcoding the % symbols. 

I use python 3.5 so I am not sure what he is expecting as output, but here is what I get

time.strftime(u"zzz{0}d{0}m{0}Y".format(chr(37)))

'zzz12112017'   # which appears to be day, month and year of today
LindsayRaabe_FPCWA
Occasional Contributor III

Great! I see where I went wrong. I just copied and pasted the expression Curits provided which was missing a bracket and I didn't notice. Worked perfectly the second time using your's Dan. Thank you both for your help! 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
StanislavaV
Occasional Contributor

Hi mr. Patterson,

your expression helped me but in the end i got table.xls with output name like this:

what else can i do to get output name like the "green bubble" output_value is showing?

thank you.

0 Kudos
curtvprice
MVP Esteemed Contributor

Open the bubble and enter: %output_value%. The text will be substituted there. Though, you need to provide a folder variable as well so you can give a full path:

%output folder%\%output_value%

anonymous55
Occasional Contributor II

Hello

I am having problem to add date to my file

I am getting this error in ArcPro

ARM_6-1642611411886.png

 

ARM_5-1642611336251.png

 

ARM_0-1642611092230.png

I am having problem to set copy features output. I tried with code here too

0 Kudos