The filter that drops the last day

Module 1: Analyze with AI, and catch its mistakes

Course outline

Quick check

Guess first, no penalty. An AI writes WHERE created_at BETWEEN '2026-09-01' AND '2026-09-30' for September sales. created_at holds a date and a time. Which orders does it miss?

A timestamp is a date plus a time, such as 2026-09-30 14:05:00. When you compare a timestamp with a plain date, the date means midnight at the start of that day. So an end date in BETWEEN quietly cuts off the last day of the month.

AI tools write BETWEEN a lot, because it reads naturally. The safer pattern is a half-open range: everything from the first day, up to but not including the day after the last.

Time zones move the edges too. If created_at is stored in UTC (the world reference time), a sale at 11 pm in New York on 30 September is already 1 October in UTC. Decide which day it belongs to, and write that rule into the prompt (the message you send to the AI).

A worked example

Filter:  WHERE created_at >= '2026-09-01'
           AND created_at <  '2026-10-01'
Rule:    created_at is UTC. Finance reports September in UTC too.
Check:   SELECT MIN(created_at), MAX(created_at) FROM ... (same filter)
Result:  2026-09-01 00:03:12   2026-09-30 23:58:40
         First and last day are both there.

Fill the gaps

Fill the gaps.

Date filter

WHERE created_at >= '2026-09-01' AND created_at Then I check the , and I say which the dates are in.

Try it

Your steps, about 2 minutes

0 of 1
  1. 1.Run MIN and MAX on the date column of one monthly report query, with the same filter, and check both edges are there. Add it to your checklist.2 min

Practice

Question 1 of 2

Which filter catches every order placed in September when created_at is a timestamp?

AI tutor

Ask about this lesson and get coached through the Try it task. The tutor is part of Learn Pro.

See Learn Pro