Query items from today's date using Python API

532
1
11-19-2021 01:53 PM
3CDCOrganizationalAccount
New Contributor III

I am not sure if this is the correct spot to ask this question, but I am trying to write code to query features created during today's date. I have figured out querying works in general;

from datetime import date
today = date.today()
query1 = Assignments.query(where="Status = 3")
query1

<FeatureSet> 29 features

But I am unsure how to do this with date types. Any suggestions?

Thanks! 

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

It can depend on the database that you're querying. If it's an enterprise geodatabase, see the reference page for how to query each of them.

In general, however, you can write the query as follows.

Assignments.query(where=f"EditDate_1 <= date '{datetime.date.today()}'")

 

- Josh Carlson
Kendall County GIS