AnsweredAssumed Answered

Query date range

Question asked by CCweedcontrol on May 17, 2018
Latest reply on May 22, 2018 by CCweedcontrol

I am trying to select features from now back to the last 180 days. I am getting an error on the expression. I am not sure but i might be going about it the wrong way. thoughts, suggestions?

 

import arcpy
import datetime
#from datetime import datetime
from datetime import timedelta

fc = r"C:\Temp\BuildingPermit.gdb\ParcelData"

arcpy.MakeFeatureLayer_management(fc, "PT_FC")
start_time= datetime.timedelta(days = 180)

end_time = datetime.datetime.now()
report_time = end_time-start_time
SQL = "created_date >="+ "'"+report_time.strftime('%Y-%m-%d %H:%M:%S')+"'"

arcpy.SelectLayerByAttribute_management("PT_FC","NEW_SELECTION", SQL)
arcpy.FeatureClassToFeatureClass_conversion("PT_FC", "C:\Temp", "BP_TestA")

Outcomes