Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Filter Google results by date from an API: a tbs cheat sheet

If you pull Google results through an API without a date filter, you mostly get evergreen pages: docs, homepages, Wikipedia, and two-year-old blog posts. Fine for rank tracking. Useless when you only want what showed up

If you pull Google results through an API without a date filter, you mostly get evergreen pages: docs, homepages, Wikipedia, and two-year-old blog posts. Fine for rank tracking. Useless when you only want what showed up yesterday or during Q1.

Google already has a built-in parameter for this: tbs. It is the same string Google puts in the browser URL when you click Tools β†’ Any time β†’ Past week. If you need a google search api date filter, passing tbs straight through your search request is the cleanest way to do it.

Here is the cheat sheet I keep around, plus what actually changes in the JSON response across three different tbs values on the same query.

The tbs cheat sheet

What you want tbs value Notes
Past hour qdr:h Incident or breaking-news checks
Past 24 hours qdr:d Daily monitoring jobs
Past week qdr:w Weekly digests
Past month qdr:m Append a number for N units, e.g. qdr:m6 = past 6 months
Past year qdr:y Annual lookups
Custom date range cdr:1,cd_min:1/1/2026,cd_max:3/31/2026 Dates must be M/D/YYYY (US order)
Sort by date sbd:1 Newest first instead of relevance
Past week + newest first qdr:w,sbd:1 Combine with a comma

Same query, three tbs settings

Using a single endpoint (POST https://api.serpbase.dev/google/search), here is a small Python snippet that runs the same query ("openai news") three ways and prints the date field from organic:

import os
import requests

URL = "https://api.serpbase.dev/google/search"
API_KEY = os.environ["SERPBASE_API_KEY"]


def run_query(query: str, tbs: str | None = None):
    payload = {"q": query, "gl": "us", "hl": "en"}
    if tbs:
        payload["tbs"] = tbs

    resp = requests.post(
        URL,
        headers={
            "X-API-Key": API_KEY,
            "Content-Type": "application/json",
        },
        json=payload,
        timeout=30,
    )
    data = resp.json()
    if data.get("status") != 0:
        raise RuntimeError(f"status={data.get('status')} id={data.get('request_id')}")
    return data.get("organic", [])


cases = [
    ("No tbs (default)", None),
    ("Past 24h (qdr:d)", "qdr:d"),
    ("Q1 2026 (cdr)", "cdr:1,cd_min:1/1/2026,cd_max:3/31/2026"),
]

for label, tbs in cases:
    items = run_query("openai news", tbs)
    dated = sum(1 for x in items if x.get("date"))
    print(f"\n=== {label} ({dated}/{len(items)} have a date) ===")
    for item in items[:3]:
        print(f"  [{item.get('date') or 'no date'}] {item['title']}")
        print(f"   {item['link']}")

What changes between the three runs:

  1. No tbs (default): Most of the top organic results have no date field at all (often only 1 or 2 out of 7–10). You get the company's own /news hub, Wikipedia, and high-authority landing pages.
  2. tbs: "qdr:d" (past 24 hours): Nearly every organic item carries a relative date string ("3 hours ago", "14 hours ago"). Evergreen hubs drop out and fresh coverage takes the top slots.
  3. tbs: "cdr:1,cd_min:1/1/2026,cd_max:3/31/2026" (custom range): Every dated result falls inside Q1 2026 ("Jan 18, 2026", "Mar 12, 2026", etc.). Useful for backfilling historical research or auditing what was published during a specific launch window.

Three details that usually trip people up

  • ISO dates fail silently. 2026-01-01 will not behave like 1/1/2026. Always format cd_min and cd_max as M/D/YYYY without leading zeros.
  • Plain English does not work. tbs is forwarded straight to Google, so "past week" or "last 24 hours" is ignored. Stick to qdr:w / qdr:d.
  • Google decides the date. If an old article gets edited and its visible "Updated on" timestamp changes, Google can include it inside qdr:d. For strict deduplication in daily monitors, store seen link values locally (SQLite or a set) instead of assuming qdr:d only returns brand-new URLs.

If you want more tested examples and edge cases (including combining tbs with raw Google search URLs), we wrote a fuller breakdown here: Google Search API Date Filter: Get Results From the Past Day, Week or a Custom Range. Full disclosure: I work on SerpBase, though the tbs syntax itself works the same anywhere Google's tbs parameter is supported.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.