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:
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!
The Calculate Value tool really makes ModelBuilder a lot more useful -- and a little Python knowledge goes a long way with that thing!
Works great! Thanks for the post.
Worked for me also, thanks mate!
Helped me too! Never too late.
thanks so much - this worked great and really helped me
Great, also see:
Formatting date as string from user input date value in ModelBuilder
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 Why won't my Date Variable work?
Retrieving data ...