I successfully used Python 3 to download data from a REST URL using the information from this link How To: Extract data from a map service using Python (esri.com).
I need help setting up my where clause when using a Date field.
Here is what worked when I used a non date field in my where clause:
params = {'where': 'RoadNumber < "00200"',
'geometryType': 'esriGeometryEnvelope',
'spatialRel': 'esriSpatialRelIntersects',
'relationParam': '',
'outFields': '*',
'returnGeometry': 'true',
'geometryPrecision':'',
'outSR': '',
'returnIdsOnly': 'false',
'returnCountOnly': 'false',
'orderByFields': '',
'groupByFieldsForStatistics': '',
'returnZ': 'false',
'returnM': 'false',
'returnDistinctValues': 'false',
'f': 'pjson',
'token': token
}
These don't work in my where clause for a date:
# Find today's date and calculate last 5 years
today = date.today()
thisyear = today.year
last5years = thisyear - 5
last5yeardate_string = str(last5years) + "-01-01 + 00:00:00"
params = {'where': 'CollisionDate >= last5yeardate_string',
params = {'where': 'CollisionDate >= (datetime.datetime.now() - dateutil.relativedelta(years=5))',