SQLite Date Format Mismatch Silently Inflated Query Results by 18x
A developer maintaining an independent AI monitoring project discovered that a routine SQLite query counting crawl runs in the last hour returned 1,252 rows when the true figure was only 68. The error stemmed from a silent string comparison mismatch: application code stored timestamps in ISO 8601 format using a 'T' separator, while SQLite's built-in datetime() function produces timestamps with a space instead. Since SQLite has no native date type and compares date strings byte by byte, the 'T' character sorted higher than a space, causing rows from the same day to incorrectly pass the filter regardless of their actual time. The bug never affected shipped production code, which consistently used JavaScript's toISOString() on both sides of comparisons, but it quietly corrupted hand-typed console queries with no error or warning. The fix is straightforward: use strftime('%Y-%m-%dT%H:%M:%SZ', 'now', '-1 hour') to ensure the cutoff string matches the stored format exactly.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in