Why Your AI's 'Since November' Is Every Order You Ever Had
Asked for revenue since November 1 and got the lifetime total. The column stores milliseconds. The filter compared it to Unix time in seconds, and every real row is about a thousand times bigger than that threshold.
You ask: "What's revenue since November 1, 2026?" The AI says $4.2 million. That is all-time revenue. November alone is about $80,000.
SELECT SUM(amount)
FROM orders
WHERE created_at >= EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-11-01 00:00:00+00')
EXTRACT(EPOCH ...) is 1793491200. That is November 1 in seconds. The column holds 1795996800123 and numbers like it. Those are milliseconds. Every one of them is about a thousand times larger than 1793491200, including orders from 2019. The filter keeps the whole table.
A thousand times is a different century, not a rounding error
Seconds and milliseconds are the same clock with the decimal point moved. Compared as integers, they are not close.
2026-11-01 00:00 UTC
seconds: 1793491200 -- 10 digits
milliseconds: 1793491200000 -- 13 digits
Two failures, depending on which side is which:
- Millisecond column, seconds threshold: every row matches. "Since November" is lifetime revenue.
- Seconds column, millisecond threshold: no row matches. "Since November" is zero.
to_timestamp(created_at) in Postgres reads seconds. Feed it a 13-digit value and the date is tens of thousands of years ahead, so "before today" is also empty. This is not a real date compared to midnight, and it is not text that sorts October before February. The type is a number. The unit is the bug.
How to fix it
Look at one raw value, then put both sides in the same unit.
-- column is milliseconds
SELECT SUM(amount)
FROM orders
WHERE created_at >= EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-11-01 00:00:00+00') * 1000
AND created_at < EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-12-01 00:00:00+00') * 1000
-- or turn the column into a timestamp first
SELECT to_timestamp(created_at / 1000.0) FROM orders LIMIT 3
Do not divide a seconds column by 1000. That turns November 2026 into January 1970, and the month filter goes empty for a new reason. Say the unit in the answer.
How to catch it
SELECT MIN(created_at) AS oldest, MAX(created_at) AS newest
FROM orders
If those are near 1,800,000,000, the column is seconds. If they are near 1,800,000,000,000, it is milliseconds. Then compare the AI's threshold to that size. A threshold a thousand times smaller than every value in the column did not filter anything.
The prompt that heads this off
Before filtering a numeric timestamp, show me MIN and MAX of the column
and say whether it is seconds (10 digits, ~1.8 billion) or milliseconds
(13 digits, ~1.8 trillion). EXTRACT(EPOCH) and UNIX_TIMESTAMP are seconds.
Date.now() is milliseconds. Put both sides in the same unit, and show me
one raw value next to the timestamp you converted it to.
The short version
A 13-digit timestamp is milliseconds. EXTRACT(EPOCH) is seconds. Compare them raw and the filter either keeps every row or keeps none. Match the units, and show one converted value before you trust the total.
Read-only MCP gateway: mcpserver.design.
Related reading: