AnsweredAssumed Answered

Query for more than 30 days

Question asked by jay.kapalczynski on May 4, 2017
Latest reply on May 4, 2017 by rvburton

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]"






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 =
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") 

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")
    if not flagDate:
        print "No rows found"