Date literals replace hardcoded dates in queries and report filters, keeping the window relative to today. Pick the right literal for the question you are asking and you eliminate most date-rollover maintenance.
- Identify the date or datetime field
Open the object's schema and confirm whether you are filtering a Date field (CloseDate, Birthdate) or a DateTime field (CreatedDate, LastModifiedDate, SystemModstamp). The literal vocabulary is the same; the expansion semantics differ slightly.
- Match the business question to a literal
Last 30 days? LAST_N_DAYS:30. Last calendar quarter? LAST_QUARTER. Last fiscal quarter? LAST_FISCAL_QUARTER. Today's records? CreatedDate = TODAY. Each business question maps to exactly one right literal.
- Write the SOQL filter
Use comparison operators (=, !=, >, >=, <, <=) for single-date literals like TODAY. Use range syntax (>= LAST_N_DAYS:30 AND <= TODAY) for explicit windows. Date literals are unquoted: LAST_WEEK, not 'LAST_WEEK'.
- Test in Developer Console
Run the query in Developer Console's Query Editor with a known dataset. Verify the row count against the same window in a report or list view. Mismatches usually mean a fiscal-vs-calendar confusion or a time-zone boundary.
- Apply the same literal to reports if applicable
In a report filter, the literal vocabulary is identical. If the SOQL gives the right count, the report filter matches. This consistency is intentional: the same date-literal engine powers reports, list views, and SOQL.
TODAY, YESTERDAY, TOMORROW. Use with = or != operators when you want exactly one day.
LAST_WEEK, THIS_MONTH, NEXT_QUARTER, LAST_90_DAYS. Aligned to calendar boundaries in the user's locale.
THIS_FISCAL_QUARTER, LAST_FISCAL_YEAR, LAST_N_FISCAL_QUARTERS:n. Respect the org's fiscal year configuration.
LAST_N_DAYS:n, N_MONTHS_AGO:n, NEXT_N_WEEKS:n. Take a colon and an integer to define the window length.
- TODAY against a DateTime field expands to the full day in the user's time zone, not the server's. A record created at 11pm UTC by a user in PST may not match the same user's TODAY filter.
- LAST_WEEK and LAST_N_DAYS:7 return different rows. LAST_WEEK is calendar-week-aligned; LAST_N_DAYS:7 is rolling. Pick the one that matches the business question.
- Fiscal literals fail silently if your org's fiscal year setup is wrong. Always confirm Setup, Company Information, Fiscal Year before relying on them.
- Date literals do not work in formula fields, validation rules, or workflow conditions. Use TODAY() and NOW() formula functions in those contexts instead.