Including a date range in V2 REST API search criteria

Does anyone know how to include a date range when using the GF REST API search criteria?

For example, look at this taken from the Docs:

https: //localhost/wp-json/gf/v2/entries?search={"field_filters": [{"key":"date_created","value":"09/10/2019","operator":"is"}]}

Is it possible to change the date created to a range of dates eg 09/10/2019 - 10/11/2019 ?

Thanks in advance,

Hello Adnaan. Please refer to the GFAPI documentation for “date range” under search filters:

Filter by date range

$search_criteria [ 'start_date' ] = $start_date ;

$search_criteria [ 'end_date' ] = $end_date ;

Thanks Chris although your answer looks like the GFAPI class rather than the REST API.

Good eye, Adnaan! I posted the link to the wrong API documentation. Check here and search for ‘search’:

search – The search criteria.
The search encompasses the following:
        status – The status of the entry. Possible values are active, spam, trash.
        The default status is active.
        mode – The type of search to apply. Possible values are all, any. The default mode is all.
        field_filters – An array of filters to search by. The array uses:
                key – The field ID.
                value – The value to search for.
                operator – The comparison operator to use. The operator defaults to =.
                Possible values are: is, =, contains, like, is not, isnot, <>, not in, in.

Did you able to find a solution? I am trying to get entries with date range as well but the documentation isn’t good for date range search.

Even the operator for a single date is not working. For example: If I want to do a search all entry after a given date. I tried to use > operator as per the documentation but It never returns correct data.

Yes I managed to do it. I don’t use this anymore but if I recall you can add kitkiple filters and so you just add one filter which is > and one filter which is < and it should narrow the date to this range.

I’ll see if I can find the code that worked for me

Yes, a code sample would be really helpful. I did try the same thing where I keep the field name date_created and set the operator to > and < for two dates. But I doesn’t seem to work for me.

See if you can find the code.

this was an endpoint i used but im afraid i can’t find the one i used to get a data range. but this might help anyway.
the form ID was 17.
The endpoint filters for entries on field 16 of $dateyday which i defined earlier in my script. there’s also an operator of “is” so its an exact match.

the string is url encoded as i used it in a php script.

have you tried playing with POSTMAN program to get it working? i strongly recommend if you haven’t. you can test any calls and it will generate the correct API call code in any programming language.,%22value%22:%22$dateyday%22,%22operator%22:%22is%22%7D%5D%7D

@user5b13b577995466.6 Thank you for your response.

Looking deep into the code base I’ve found how to do the search with date range. The documentation should cover this because it is such an important filter.

You need to use special filters start_date & end_date with any date format that is supported by PHP new Date($str) class. I prefer to use YYYY-MM-DD because this is what MYSQL uses.

So, to get entries between two dates you will need to do query like below:{"start_date":"2021-04-01", "end_date": "2021-04-02"}

I hope it helps!

1 Like

That’s great! Thanks for posting this.

Thank you for sharing that information Sisir.