Select records based on two dates in Python from Arcgis Online

370
1
12-20-2022 06:42 AM
ChallagundlaSindhuraITS
New Contributor II

Hi,

How do I Pull the data based on two dates in Python from ArcGIS Online?

The below code works for single date:

 

feature_layer_id = ''

Inspform = gis.content.get(feature_layer_id)

from datetime import datetime, timedelta
insp=Inspform.layers[0].query().sdf #.sdf get as a pandas dataframe
last_24hour_date_time = datetime.now() - timedelta(hours = 3200) 
timestamp = last_24hour_date_time.strftime('%Y-%m-%d %H:%M:%S')
filterinsp = insp[insp['CreationDate'] >= timestamp]
sinsp = filterinsp.astype({"SHAPE":str}) #should convert else error
sinsp

 

I am trying to add another date to compare, the below code doesn't work: It says invalid syntax at OR

from datetime import datetime, timedelta
insp=Inspform.layers[0].query().sdf #.sdf get as a pandas dataframe
last_24hour_date_time = datetime.now() - timedelta(hours = 😎 #replace it with 24 hours and use append ,3200
timestamp = last_24hour_date_time.strftime('%Y-%m-%d %H:%M:%S')
filterinsp = insp [ [insp['CreationDate'] >= timestamp] OR [insp['EditDate'] >= timestamp] ]
sinsp = filterinsp.astype({"SHAPE":str}) #should convert else error
sinsp

 

 

 

 

Tags (3)
0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - Esri Community

will get rid of that cool emoji in your code and provide line numbers to help others

Are you sure OR isn't lowercase (eg. or )


... sort of retired...
0 Kudos