time.strftime("%d/%m/%Y")
I was googling how to do something similar and this little discussion eventually lead me to my solution.
It can be done by placing a Calculate Value Tool in your model and setting its expression to:
time.strftime("%Y%m%d")
The output value will be a date or time in the format you specify between the "s. This link has a nice table with helpful explanations about the different date and time formatting options and possible associated limitations or restrictions: 8.1. datetime - Basic date and time types - Python v2.7.8 documentation.
My example has the particular format(%Y%m%d) such that if the model were run on June 8, 2001, the output value from the tool would be the string '20010608'.
You can then rename the output value(green bubble) to ANYTHING and then elsewhere in your model you can reference that value by inserting %ANYTHING% into filenames or location dialogues throughout the rest of the model, just like other in-line variables.
I hope this helps you out, 3½ years late, or more likely, somebody else with the same question.
Thanks for posting Ryan Stillman - your late reply helped me figure this out!
Thank you for posting this - it worked perfectly.
Helped me too, thanks for posting!
Odd, the example doesn't seem to work for me. I'm running 10.3.1. If I run in a python script it works fine but not so much in Model Builder where the variable is assigned a "1". Any suggestions?
William, I was having the same issue but then I connected the output date (green bubble) as a precondition variable to the tools (yellow bubble) that I ran and it worked for me!
I seem to be having similar issues. I was getting the "1" output but now I get the date but also keep getting errors about incorrect naming. Can anyone tell me what name is wrong? The original demo tool provided further up has the same issue!
I answered here https://community.esri.com/thread/204767-why-wont-my-date-variable-work
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.