Back to Blog

Why Your AI's 'This Month' Number Includes Last September Too

Asked for September signups and the count is huge. EXTRACT(MONTH FROM created_at) = 9 matches every September in the table — 2024, 2025, 2026. 'This month' needs a date range, not a month number.

You ask for "signups this month." The number is 4× what the admin dashboard shows. The SQL has no join, no OR leak, no missing HAVING. It used EXTRACT(MONTH FROM created_at) = 9. That is every September you have ever stored.

A month number is not a period

-- every September in the table
WHERE EXTRACT(MONTH FROM created_at) = 9

-- MySQL-shaped same bug
WHERE MONTH(created_at) = 9

September 2024 + 2025 + 2026 all pass. If you've been live two years, "this month" is three Septembers. The query is valid. The English is not.

-- this calendar month (half-open; includes the last day)
WHERE created_at >= DATE_TRUNC('month', NOW())
  AND created_at <  DATE_TRUNC('month', NOW()) + INTERVAL '1 month'

Name the timezone if NOW() is UTC and "this month" is Bangkok — that's the timezone trap, stacked on top. The extract bug happens even in one timezone.

This is the over-count cousin of BETWEEN missing the last day. That one is a short month. This one is too many years.

EXTRACT(WEEK) / WEEK() has the same shape: week 37 of every year, plus ISO vs US week numbering. Prefer a range for "this week" too.

How to catch it

Ask for MIN(created_at) and MAX(created_at) on the filtered rows. If the min is last year, the filter was a month number, not a period. Compare to a known dashboard number for this September only.

The prompt that heads this off

When I say this month / this week / September, use a timestamp range
(>= start AND < day after the period), not EXTRACT(MONTH) or MONTH().
Those match every year. Show MIN and MAX of the filtered dates.

The short version

MONTH = 9 means "any September." "This month" means one range. If the number looks like several years of that month stacked, read the WHERE before you read the join.


Read-only MCP gateway: mcpserver.design.

Related reading: