SerpBase
Back to Blog

Google Search before: and after: Operators via API

Add before:YYYY-MM-DD or after:YYYY-MM-DD to a Google query to limit results by date. Both tested: dates in the answer and the one catch to know.

December 2, 2026
By SerpBase Team2 min read

Short answer: add before:YYYY-MM-DD or after:YYYY-MM-DD to the query you send to /google/search. Google limits the results to pages it dates before or after that day. Use both for a window.

The request

curl -X POST 'https://api.serpbase.dev/google/search' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -d '{"q":"openai gpt announcement after:2026-11-01","gl":"us","hl":"en","device":"desktop"}'

What came back

We ran the same words with each operator on 2 December 2026:

after:2026-11-01 — 7 results. The dates on them were "2 hours ago", "6 hours ago", "7 hours ago", "10 hours ago", "Nov 10, 2026" and "Nov 18, 2026": all inside the window. One social-media result had no date.

before:2024-01-01 — 7 results, mostly 2022–2023 pages:

ranktitledate
2Introducing ChatGPTNov 30, 2022
3GPT-4Mar 14, 2023
4Introducing GPTsNov 6, 2023
5OpenAI announces leadership transitionNov 17, 2023

Rank 1 was the publisher's news index page, dated Mar 31, 2016: an old page that is still updated. That is what "before" means to Google — the date it holds for the page, not when the content you see was written.

Python: a dated window

import requests

def search_window(words, start, end):
    q = f"{words} after:{start} before:{end}"
    r = requests.post(
        "https://api.serpbase.dev/google/search",
        headers={"X-API-Key": "YOUR_API_KEY"},
        json={"q": q, "gl": "us", "hl": "en", "device": "desktop"},
        timeout=60,
    ).json()
    if r["status"] != 0:
        raise SystemExit(r.get("error"))
    return [(i["rank"], i.get("date"), i["title"]) for i in r.get("organic", [])]

for row in search_window("openai gpt announcement", "2023-01-01", "2023-12-31"):
    print(row)

Things that trip people up

  • date is Google's text. It can be "7 hours ago" or "Nov 18, 2026", and is missing on some results. Parse both forms, and keep undated results separate.
  • Operators or tbs? before:/after: live in the query and travel with it anywhere. The tbs parameter (qdr:d, custom ranges) is Google's search-tools filter; see the date filter guide. Pick one per request.
  • Fewer results is normal. Narrow windows often return fewer than 10 organic results.
  • Use ISO dates. 2026-11-01 is unambiguous across countries and languages.

Related

Cost and docs

A Google search is 1 credit, with or without operators. Failed requests are not charged, and new accounts get 500 free credits.