Can ArcGIS Pro ModelBuilder append today's date to output table filename?

2906
11
Jump to solution
04-08-2019 10:05 PM
BenVan_Kesteren1
Regular Contributor

I have created a simple tool which finds all properties that lay within a polygon feature (select layer by location), and then exports to a filegeodatabase (Feature class to feature class). 

I am wondering if I can get the output filename to be dynamic, and include today's date in the feature class filename each time it is run?

Currently it exports LandParcelRateParking, if I run it each week it simply overwrites last weeks table. Can I get it to append to the filename to be something like:

LandParcelRateParking05042019

LandParcelRateParking09042019

etc

The model is as per below screenshot:

I am guessing there is something I can do to append the date, but I am missing it.... 

Cheers

0 Kudos
2 Solutions

Accepted Solutions
rachelg_esri
Esri Contributor

Hello Ben!

I believe you can use Calculate Value and some Python code to get what you're looking for. I made the following test model and it appears to have done what you're looking for:

Model showing Calculate Value and Table to Table using Inline Variables

In Calculate Value, I have the following:

Expression:

gettime()

Code Block:

def gettime():
   from datetime import datetime
   now = datetime.now()
   forFile = now.strftime("%m%d%Y")
   return forFile

This uses the Python "DateTime" module that allows you to grab your machine's current time and modify the output structure using various abbreviations (ex. %m for month, %d for day, %Y for four-number year).

I then set the output of the Calculate Value to a specific name (Value in this case), and then called upon that value within the output name of the table.

The resulting table was called "AfterTable_04092019".

For more information, I'd recommend reviewing the following:

Enjoy!

Best regards,

Rachel

Esri Support Services

Rachel Guttmacher
ArcGIS Online Technology Lead
Esri Support Services

View solution in original post

KyleConboy
New Contributor II

Thanks for the help.  This thread provided the needed solution.  The inline variable referencing the calculated variable was what i wasn't getting before. 

Thanks again:)

View solution in original post

11 Replies
rachelg_esri
Esri Contributor

Hello Ben!

I believe you can use Calculate Value and some Python code to get what you're looking for. I made the following test model and it appears to have done what you're looking for:

Model showing Calculate Value and Table to Table using Inline Variables

In Calculate Value, I have the following:

Expression:

gettime()

Code Block:

def gettime():
   from datetime import datetime
   now = datetime.now()
   forFile = now.strftime("%m%d%Y")
   return forFile

This uses the Python "DateTime" module that allows you to grab your machine's current time and modify the output structure using various abbreviations (ex. %m for month, %d for day, %Y for four-number year).

I then set the output of the Calculate Value to a specific name (Value in this case), and then called upon that value within the output name of the table.

The resulting table was called "AfterTable_04092019".

For more information, I'd recommend reviewing the following:

Enjoy!

Best regards,

Rachel

Esri Support Services

Rachel Guttmacher
ArcGIS Online Technology Lead
Esri Support Services
Tim-Woodfield
New Contributor III

Hi Rachel,

I used your code above but my value isn't coming back as a date. It is coming back as just the number 1. Does the Data type need to be set to something specific? I'm doing this in ArcMap and not Pro also. Would this cause the problem?

Thanks!

EDIT: Just realized that the value being returned is 1 no matter what the expression is. I can set it to 1+1 and it still returns 1. 

0 Kudos
curtvprice
MVP Esteemed Contributor

When you right click Calculate Value what is the message (Value = ?)

I would set the data type to string, and then connect this as a precondition to the tool where you are going to use the string in the output name.

0 Kudos
JasminePrater
New Contributor III

This worked well for me when trying to add the date to the end of a file name after a reconcile log was created.  I calculated the date value using your script, renamed the log file using %Value% at the end, and set a precondition of Value having been calculated.  Thank you!

KyleConboy
New Contributor II

I'm trying to do something similar,  I'm looking to copy a file geodatabase on a quarterly basis and have it saved with the same name and the date on the end of the geodatabase name.  'Table to table' will not work in this workflow and it does not look like copy will either.  Any ideas?

0 Kudos
rachelg_esri
Esri Contributor

Hello Kyle,

Can you clarify on "'Table to table' will not work in this workflow and it does not look like copy will either". The Copy tool does copy geodatabases, and the above workflow should work with this tool. Are you receiving an error? What's the issue on your end? Thanks!

Best regards,

Rachel

Esri Support Services

Rachel Guttmacher
ArcGIS Online Technology Lead
Esri Support Services
0 Kudos
KyleConboy
New Contributor II

Hi Rachel.  It doesn't look like table to table will let me input a file geodatabase and copy doesn't have anywhere to load in Python code.  

0 Kudos
curtvprice
MVP Esteemed Contributor

Table To Table takes a specific table input not a geodatabase input. You can batch copy a bunch of tables with this tool though: Table to Geodatabase

Copy is accessible in python as arcpy.Copy_management.

Hope this is helpful.

KyleConboy
New Contributor II

Thanks for the help.  This thread provided the needed solution.  The inline variable referencing the calculated variable was what i wasn't getting before. 

Thanks again:)