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
Solved! Go to Solution.
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:
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
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:)
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:
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
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.
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.
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!
This is great! Thank you for this!!
One thing I ran into which is strange... the output is writing "unknown" after the date. Do you know what I might be doing wrong? I copied your exact code.
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?
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
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.
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.