Inserting Current Date into Filename via Modelbuilder

02-04-2011 05:46 AM
New Contributor III
Is there a way to programmatically export a shapefile or feature class from Modelbuilder that has the current date in its filename?
17 Replies
Esri Regular Contributor

I'm assuming you're on 10.
Check the toolbox I've attached. You dont need to script this.
You'll see its just a copy features and a Calc Value.
The Calc value has a python snippet to calc the date. The output of this is "outDate"

I've then used the inline variable %outDate% as the name of the featureclass.

I grabbed the snippet from:
Depending on how you write out

(d/MM/yyyy etc etc), you can get different dates. Also remember the featureclass name cant start with a number.
New Contributor II

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.

New Contributor

Thanks for posting Ryan Stillman‌ - your late reply helped me figure this out!

0 Kudos
New Contributor II

Thank you for posting this - it worked perfectly.

0 Kudos
New Contributor III

Helped me too, thanks for posting!

0 Kudos
MVP Esteemed Contributor

The Calculate Value tool really makes Model Builder​ a lot more useful -- and a little Python knowledge goes a long way with that thing!

Occasional Contributor

Works great! Thanks for the post.

0 Kudos
New Contributor II

Thank you!! 

0 Kudos
New Contributor

Worked for me also, thanks mate!

0 Kudos