I am sure this is probably a simple syntax fix but I receive invalid syntax errors during the Select Analysis when trying to select records where the date field in my file geodb (ISS_CST) is greater than the date variable. I have tried a couple different lines but they do not work.
dayDateStr = '120621'
dayDate10DaysAgo = datetime.datetime.strptime(dayDateStr, "%m%d%y") - timedelta(days=10)
print (dayDate10DaysAgo)
#arcpy.Select_analysis(warningsSel2, warningsSel2a, "!ISS_CST! >" dayDate10DaysAgo)
arcpy.Select_analysis(warningsSel2, warningsSel2a, "ISS_CST > date" +dayDate10DaysAgo+"")
>> 2021-11-26 00:00:00
File "weatherloader_Test_Warnings.py", line 279, in ProcessWarnings arcpy.Select_analysis(warningsSel2, warningsSel2a, "ISS_CST > date" +dayDate10DaysAgo+"") TypeError: cannot concatenate 'str' and 'datetime.datetime' objects
If I use the line currently commented out the error is:
File "weatherloader_Test_Warnings.py", line 278 arcpy.Select_analysis(warningsSel2, warningsSel2a, "!ISS_CST! >" dayDate10DaysAgo) ^ SyntaxError: invalid syntax
dayDateStr
would actually be.str.format()
to format the exact query string in the format expected. The expected format varies by data source type, so you need to specify that, too. Please Edit the question so that it reflects both the data source type (shapefile, file geodatabase,...) and the exact contents of thewhere_clause
.