How to use the dateRestrict parameter in the custom search API
I am trying to change some Java code that Google API uses. One of the features I was unable to get is dateRestrict. Information on this can be found here: GoogleAPI
To implement this, I append the following line after my request. It links correctly to the full url because other parameters work with it.
String parameters = "&dateRestrict=2012-01-01";
I have also tried 1d and 1m but they neither work as parameters
If anyone could show me an example of dateRestrict I would really appreciate it. I just don't understand how they want to use it in the API. Thank.
In Using REST to Call an API, you can find information about the parameter dateRestrict
. Parameter Notes: Limits results to URLs based on date. Supported values:
- d [number]: Queries results from the specified number of past days.
- w [number]: Queries results from a specified number of past weeks.
- m [number]: Queries results from a specified number of past months.
- y [number]: Queries results from a specified number of past years.
For me, the use case should look like this:
String parameters = "&dateRestrict=d20";
or
String parameters = "&dateRestrict=y1";
I think you can play with the API for this method to understand this setting better.
Also see:
- Looking for an urgent solution regarding the Google Custom Search API with Date Limit Option
I tried to do the same and dateRestrict for absolute time range didn't seem to work. There were also pages that were not in the date range. The workaround I have found is to use the sort function. The request will look something like this:
(q = 'search_term', cx = 'search_engine_id', sort = 'date: r: yyyymmdd: yyyymmdd')
The sort function allows you to sort and filter the date of the results up to a specified time range.