I am trying to rename shapefile with date (.format)

Question:

Hello I am getting error for this code I couldn’t find the problem

Error:
File "C:Scheduleopen_restaurants.py", line 74
    txtFileNameNoExt = "{}_{}".format(os.path.splitext(txtFileNameWithExt)[0], datetime.datetime.now(%y_%m_%d))
                                                                                                     ^
SyntaxError: invalid syntax
#rename shapefile
txtFileNameWithExt = "Open_Restaurants.shp"
txtFileNameNoExt = "{}_{}".format(os.path.splitext(txtFileNameWithExt)[0], datetime.datetime.now(%y_%m_%d))
arcpy.env.workspace = my_Path
arcpy.Rename_management(txtFileNameWithExt,"{}.shp".format(txtFileNameNoExt))
Asked By: Kylie

||

Answers:

change datetime part to

datetime.datetime.now().strftime('%y_%m_%d')

docs: datetime module strftime

Answered By: marmeladze
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.