The filter that drops the last day

Module 1 : Analyze with AI, and catch its mistakes

Plan du cours

Cette leçon n'est pas encore dans votre langue, la voici donc en anglais.

Petit test

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.

Complétez les trous

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

Vos étapes, environ 2 minutes

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

Exercices

Question 1 sur 2

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

Tuteur IA

Posez vos questions sur cette leçon et faites-vous guider dans l'exercice « Essayez ». Le tuteur fait partie de Learn Pro.

Voir Learn Pro