Trying to query records for older than 30 days from present....
Blowing up here...dont have to proper syntax,,,,I am trying to use two variables..
expDateMonthAgo = "CreationDate = [month_ago]"
Thoughts?
arcpy.env.workspace = "C:\\Users\\xxxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\xxxx_Admin.sde"
fc = "xxxxx"
var_additionalcomments = 'additionalcomments'
var_CreationDate,var_Creator = 'CreationDate','Creator'
headers = ['comments','Creation Date','Creator']
QueryFields = [var_additionalcomments,var_CreationDate,var_Creator]
import datetime as DT
today = DT.date.today()
month_ago = today - DT.timedelta(days=30)
print month_ago
expDateMonthAgo = "CreationDate = [month_ago]"
expDate = "({})".format(expDateMonthAgo)
expressionDate = expDate
outFileRegionDate = open(r"E:\ArcGISProjects\\PythonScripts\PythonSync\PythonScripts\z_outFileRegionDate.csv", "w")
mylist=[]
with arcpy.da.SearchCursor(fc, QueryFields, where_clause=expressionDate) as cursorDate:
outFileRegionDate.write(','.join(headers) + '\n')
flagDate = False
for row in cursorDate:
flagDate = True
zvalDate = str('{0},{1},{2}'.format(row[0],row[1],row[2]))
outFileRegionDate.write(zvalDate + "%s\n")
mylist.append(zvalDate)
if not flagDate:
print "No rows found"
outFileRegionDate.close()