Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

Query feature service using a date - sample #226

Closed gEYEzer closed 8 years ago

gEYEzer commented 8 years ago

Could you possibly provide a sample of querying a feature service that gets features with a CreationDate > today at 00:00:00? The rest endpoint query task will take a where clause like:

CreationDate > date '2016-4-25 07:00:00'

But I can't get that where clause to work in your create_replica_portal_item.py sample. I get an error of "Unable to export item "

This is the code from your sample that creates the replica:

` admin = arcrest.manageorg.Administration(securityHandler=shh.securityhandler)

            item = admin.content.getItem(itemId)
            user = admin.content.users.user(username=item.owner)
            dateQueryString = "CreationDate > " + getDateQueryString()
            print dateQueryString

            exportParameters = {"layers":[
                                   {
                                       "id": 0,
                                       "where": dateQueryString
                                       }]
                               }
            res  = user.exportItem(title=exportZipFile,
                                itemId=itemId,
                                exportFormat="File Geodatabase",
                                exportParameters=exportParameters,
                                wait=True)

`

Many thanks.

gEYEzer commented 8 years ago

I just tried converting the date to a float using arcresthelper.common.local_time_to_online and got the same result. "Unable to export Item:

DShokes commented 8 years ago

Dates are weird in in REST. Even though the query returns dates as numbers, the where parameter for Query is string like '2016-4-25 07:00:00' without the "date" before it. The documentation is wrong. Additionally, the date must be a number where applying editing. Dates can be cumbersome to work with. Hope that helps.

gEYEzer commented 8 years ago

Thanks @DShokes, that was my problem. My query string needed to look like: "CreationDate > '2016-4-27'"