I'm trying to select all the features in a feature class that have been edited in the past day. I'm using SelectLayerByAttribute_management and I keep getting an error on the SQL query and was hoping someone could give me a hand.
In the code below lyr is the feature class being evaluated and MOD_DATE is the date field being checked.
yesterday = date.today() - timedelta(1) yesterdaysDate = yesterday.strftime("%m/%d/%y %I:%M:%S") SQL_statement = "MOD_DATE >= 'yesterdaysDate'" arcpy.MakeFeatureLayer_management(lyr, "FEATURE_SELECTION") arcpy.SelectLayerByAttribute_management("FEATURE_SELECTION", "NEW_SELECTION", SQL_statement)
SQL_statement = "MOD_DATE >= '"+yesterdaysDate+"'"
And, noting Joshua Bixby's comment below, you may need to proceed your date with the word "date" (if using a file geodatabase, for example):
SQL_statement = "MOD_DATE >= date '"+yesterdaysDate+"'"
Seeing I don't know what back-end database is hosting your data, I can't offer a specific suggestion. In general, dates and times are handled differently depending on the back-end database: SQL reference for query expressions used in ArcGIS—Help | ArcGIS Desktop