I Inqua
Sign in Get started
Cheat sheet

SOQL date literals: the complete cheat sheet

Updated June 9, 2026 · 6 min read · by the Inqua team

Filtering by date is the single most common thing people do in SOQL — and the place where SQL habits break first. SOQL has no GETDATE() or DATEADD(). Instead it ships with date literals: unquoted keywords like TODAY, THIS_QUARTER, and LAST_N_DAYS:30 that Salesforce expands into date ranges for you. This cheat sheet covers every literal, with examples and the gotchas that break queries.

How date literals work

A date literal is written bare — no quotes — wherever a date value would go in a WHERE clause. Salesforce evaluates it at query time, in the time zone of the user running the query:

SELECT Id, Name, Amount, CloseDate
FROM Opportunity
WHERE CloseDate = THIS_QUARTER AND IsClosed = false

Range-style literals like THIS_MONTH match any value inside the range, so = reads as "falls within". You can also compare with <, >, <=, and >= — for example CloseDate > NEXT_WEEK means "after the end of next week".

Fixed-range literals

LiteralMatches
YESTERDAY / TODAY / TOMORROWThe full 24 hours of that day.
LAST_WEEK / THIS_WEEK / NEXT_WEEKSeven full days; the week's start day depends on your locale.
LAST_MONTH / THIS_MONTH / NEXT_MONTHThe full calendar month.
LAST_90_DAYS / NEXT_90_DAYSA rolling 90-day window ending (or starting) today.
LAST_QUARTER / THIS_QUARTER / NEXT_QUARTERThe full calendar quarter — see the fiscal variants below.
LAST_YEAR / THIS_YEAR / NEXT_YEARThe full calendar year.

Rolling-range literals (the :n family)

These take a number after a colon and build a window relative to now:

LiteralMatches
LAST_N_DAYS:nFrom midnight n days ago up to the current moment — note this includes today.
NEXT_N_DAYS:nFrom midnight tomorrow through the next n days.
LAST_N_WEEKS:n / NEXT_N_WEEKS:nWhole calendar weeks before/after the current week.
LAST_N_MONTHS:n / NEXT_N_MONTHS:nWhole calendar months before/after the current month.
LAST_N_QUARTERS:n / NEXT_N_QUARTERS:nWhole calendar quarters before/after the current quarter.
LAST_N_YEARS:n / NEXT_N_YEARS:nWhole calendar years before/after the current year.
N_DAYS_AGO:nExactly the single day n days ago (also available for weeks, months, quarters, and years: N_MONTHS_AGO:n, etc.).

For example, cases opened in the last 30 days (including today):

SELECT Id, CaseNumber, Subject
FROM Case
WHERE CreatedDate = LAST_N_DAYS:30

Fiscal period literals

Plain THIS_QUARTER is the calendar quarter. If your company's fiscal year is configured in Salesforce Setup, use the fiscal variants to match how your business actually reports:

  • LAST_FISCAL_QUARTER / THIS_FISCAL_QUARTER / NEXT_FISCAL_QUARTER
  • LAST_FISCAL_YEAR / THIS_FISCAL_YEAR / NEXT_FISCAL_YEAR
  • LAST_N_FISCAL_QUARTERS:n / NEXT_N_FISCAL_QUARTERS:n
  • LAST_N_FISCAL_YEARS:n / NEXT_N_FISCAL_YEARS:n
  • N_FISCAL_QUARTERS_AGO:n / N_FISCAL_YEARS_AGO:n

For example, won revenue so far this fiscal year:

SELECT SUM(Amount)
FROM Opportunity
WHERE IsWon = true AND CloseDate = THIS_FISCAL_YEAR
Tired of looking up which literal you need? Ask the question in plain English — Inqua writes and runs the SOQL for you, and shows the exact query behind every answer so you can learn the syntax as you go.

Absolute dates and datetimes

Literal dates are also written without quotes. Date fields take YYYY-MM-DD:

SELECT Id FROM Opportunity WHERE CloseDate >= 2026-07-01

Datetime fields need a full ISO 8601 value with a time zone — a bare date here is an error:

SELECT Id FROM Case
WHERE CreatedDate >= 2026-06-01T00:00:00Z
  AND CreatedDate < 2026-07-01T00:00:00Z

The half-open pattern above (>= the first of the month, < the first of the next month) is the reliable way to ask "everything in June" against a datetime field.

The gotchas that break date queries

  • Never quote a literal. WHERE CloseDate = 'THIS_QUARTER' treats it as a string and fails — literals are keywords, not values.
  • Date vs. datetime fields differ. CreatedDate is a datetime, so comparing it to a bare 2026-06-09 is an error. Date literals like TODAY work on both field types, which is one more reason to prefer them.
  • LAST_N_DAYS includes today. It runs from midnight n days ago up to the current second. If you want "the 7 days before today, excluding today", you need explicit bounds.
  • Weeks follow your locale. THIS_WEEK may start Sunday or Monday depending on the running user's locale settings.
  • Quarters are calendar unless you say FISCAL. If your fiscal year starts in February, THIS_QUARTER and THIS_FISCAL_QUARTER return different rows.
  • Results depend on the user's time zone. Literals are evaluated in the time zone of whoever runs the query — two users in different time zones can get different rows for TODAY.

Putting it together

Opportunities closing this fiscal quarter, broken down by stage:

SELECT StageName, COUNT(Id), SUM(Amount)
FROM Opportunity
WHERE CloseDate = THIS_FISCAL_QUARTER AND IsClosed = false
GROUP BY StageName

Grouped queries like this one are covered in depth in our guide to SOQL aggregate queries — and if you're translating habits from another database, start with SOQL vs SQL.

Or skip the syntax entirely

Inqua turns plain-English questions into live SOQL against your real org — and shows the exact query behind every answer, so you learn the syntax as you go. Read-only, OAuth-only, free during early access.

The demo runs on sample data — no Salesforce org required.