Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Date Literal entry
How-to guide

How to use date literals in a SOQL query or report filter

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.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 20, 2026

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.

  1. 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.

  2. 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.

  3. 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'.

  4. 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.

  5. 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.

Key options
Single-day literalsremember

TODAY, YESTERDAY, TOMORROW. Use with = or != operators when you want exactly one day.

Calendar-period literalsremember

LAST_WEEK, THIS_MONTH, NEXT_QUARTER, LAST_90_DAYS. Aligned to calendar boundaries in the user's locale.

Fiscal-period literalsremember

THIS_FISCAL_QUARTER, LAST_FISCAL_YEAR, LAST_N_FISCAL_QUARTERS:n. Respect the org's fiscal year configuration.

Parameterized literalsremember

LAST_N_DAYS:n, N_MONTHS_AGO:n, NEXT_N_WEEKS:n. Take a colon and an integer to define the window length.

Gotchas
  • 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.

See the full Date Literal entry

Date Literal includes the definition, worked example, deep dive, related terms, and a quiz.