Anyone know how to make python put a date stamp on a filename when creating a feature?
Thanks,
Steve
Solved! Go to Solution.
Here is how I had to code it:
import time
from datetime import Date
#Sets a variable to hold today's date
currentdate = today()
Process: Feature Class to Feature Class (6)
arcpy.FeatureClassToFeatureClass_conversion(in, out loc, "output_"+str(currentdate)
The result is: output_2014-10-23
The “-“ causes failure as an invalid character
Hi Steve,
Can you clarify your question a little? Are you looking to put a date stamp on a new feature class? I've written a few scripts that utilize dates and times and the method changes a little based on where you want to put the data. Let me know and I can try to help.
Thanks,
Brandon
Hi Brandon,
Yes on a new feature class. I am running a feature to feature script that filters specific data for each feature and I need to date stamp them so that I can view changes in a side by side comparison and the output goes into a File Geodatabase.
Thanks,
Steve
And you would like the date stamp to be on the feature class? So you could check today's "River" export against yesterday's "River" feature class? If I'm understanding you right then I would suggest importing datetime. Depending on how you want to format the date you have some options shown here 8.1. datetime — Basic date and time types — Python 2.7.8 documentation
import datetime
#Set a variable to hold today's date
currentdate = datetime.date.today()
#Execute the feature to feature function. Casting as a string just to be safe
arcpy.FeatureClassToFeatureClass_conversion(in_features, out_path, out_name + str(currentdate))
Yes, that is basically what I am trying to do, I will give that a try and let you know how it goes.
Thanks for your quick responses,
Steve
You're welcome and good luck. If it gives you trouble let me know and I can try to help.
Brandon
Thanks
Happy to,
I'm not sure how you ended up coding it but you can modify your date object with .strftime which lets you tell the date objects how to orient themselves. There is a really good reply on stack overflow datetime - How to print date in a regular format in Python? - Stack Overflow
But in your case I would say code like currentdate.strftime(%Y%b%d) should format it the way you want. You can reference the formatting letters in either the link or the help for strftime.
Good luck,
Brandon
Here is how I had to code it:
import time
from datetime import Date
#Sets a variable to hold today's date
currentdate = today()
Process: Feature Class to Feature Class (6)
arcpy.FeatureClassToFeatureClass_conversion(in, out loc, "output_"+str(currentdate)
The result is: output_2014-10-23
The “-“ causes failure as an invalid character