DATE Clause in SOQL (Salesforce Object Query Language)

To filter by date in SOQL, compare a Date or DateTime field with a value written without quotes (CloseDate > 2026-10-31, CreatedDate >= 2026-10-06T00:00:00Z) or with a date literal such as TODAY, LAST_N_DAYS:7 or THIS_MONTH. To compare a DateTime field with a plain date, wrap it in DAY_ONLY(), and add convertTimezone() when the day must follow the user’s time zone.

I ran every query below with the Salesforce CLI against a Salesforce Developer Edition org, including the four mistakes that produce most date errors. One test shows why a record created “yesterday” can disappear from a DAY_ONLY() filter, which few tutorials explain.