The filter that drops the last day

Módulo 1: Analyze with AI, and catch its mistakes

Conteúdo do curso

Esta aula ainda não está no seu idioma, então aqui está em inglês.

Teste rápido

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.

Preencha as lacunas

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

Seus passos, cerca de 2 minutos

0 de 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

Exercícios

Pergunta 1 de 2

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

Tutor de IA

Tire dúvidas sobre esta aula e tenha ajuda na tarefa do “Experimente”. O tutor faz parte do Learn Pro.

Ver o Learn Pro