SQL Date, Time Zone and Period Logic Audit
Check a SQL report for date boundary errors, time zone mix-ups, inclusive or exclusive ranges and period comparisons that quietly mislead.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
[VERIFY] is an editorial flag, not a blank to fill. Wherever the prompt shows [VERIFY], check that item against a reliable source before you use it.
Please audit the date and time logic in my SQL. Database: [DATABASE_TYPE]. Query: [QUERY]. Column types for every date or timestamp column used: [DATE_COLUMN_TYPES]. Time zone of the stored data and of the people reading the report: [STORED_TZ_AND_REPORT_TZ]. The report claims to show: [REPORT_CLAIM], for example "orders per calendar month". Look for: BETWEEN used with timestamps and missing the last day, comparisons of dates with timestamps, truncation in the wrong zone, month length and leap-year assumptions, week-start differences, daylight saving effects, comparing partial current periods to full prior periods, and filters on a formatted string rather than a real date. Present: 1) A table with the columns Clause, Issue, Example of a row it would misplace (using invented data), and Fix. 2) A rewritten date filter using a half-open range (greater than or equal to the start, less than the next start). 3) Three test queries that count rows near the boundaries so I can confirm the fix. 4) A short note on whether the totals will change after the fix, and how to explain that to report readers. Date functions and time zone syntax differ by database, so mark each function used [VERIFY] for [DATABASE_TYPE]. Do not guess the stored time zone; ask me. Test on a copy before replacing a live report. Add a worked example with invented figures: an order stamped 2025-03-31 18:30 fails a filter ending at 2025-03-31 00:00; show which rows are lost and the corrected range.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.