SOQL Date/DateTime Literal Formatter

Convert a date or datetime into exact SOQL literal syntax — DST-aware, ready to paste into a query.

Timezone

SOQL DateTime values are stored in UTC, but you usually need to reason about them in a local timezone — and DST shifts that UTC offset partway through the year. This tool applies the correct offset for the date you're converting, not just the current one.

Pick a date & time (or paste one) to see the SOQL literals.

Why SOQL dates trip up people who already know SQL

If you're coming from standard SQL, the instinct is to wrap dates in quotes — WHERE CloseDate = '2026-08-13'. In SOQL, that's wrong. Date literals and date values in SOQL are written without quotes: WHERE CloseDate = 2026-08-13. Quote it like a string and the query either fails or silently doesn't match what you expect, which makes it one of the more common gotchas for developers moving from traditional SQL into Salesforce.

Date literals are the other half of the story. SOQL supports relative keywords like THIS_MONTH, LAST_N_DAYS:7, and NEXT_N_YEARS:2 that resolve dynamically at query time — no manual date math required, and no need to hardcode a value that goes stale tomorrow. LAST_N_DAYS:7, for example, includes today plus the seven days before it, which surprises people expecting it to mean strictly “the previous 7 days, not including today.”

This tool handles the conversion between a normal date and the exact format SOQL expects, so you're not hand-editing query strings and re-testing every time the format trips you up.

SOQL relative date literal reference

These are used directly in SOQL, unquoted — there's nothing to convert. This is a reference, not a converter.

Daily

  • YESTERDAY, TODAY, TOMORROW

Weekly

  • LAST_WEEK, THIS_WEEK, NEXT_WEEK
  • LAST_N_WEEKS:n, NEXT_N_WEEKS:n
  • N_WEEKS_AGO:n

Monthly

  • LAST_MONTH, THIS_MONTH, NEXT_MONTH
  • LAST_N_MONTHS:n, NEXT_N_MONTHS:n
  • N_MONTHS_AGO:n

Rolling 90-day

  • LAST_90_DAYS, NEXT_90_DAYS
  • LAST_N_DAYS:n, NEXT_N_DAYS:n
  • N_DAYS_AGO:n

Quarterly

  • THIS_QUARTER, LAST_QUARTER, NEXT_QUARTER
  • LAST_N_QUARTERS:n, NEXT_N_QUARTERS:n
  • N_QUARTERS_AGO:n

Yearly

  • THIS_YEAR, LAST_YEAR, NEXT_YEAR
  • LAST_N_YEARS:n, NEXT_N_YEARS:n
  • N_YEARS_AGO:n

Fiscal

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

Requires custom fiscal years to be configured in Setup.

Frequently asked questions

Do I need to quote SOQL date literals?

No — unlike a standard SQL date string, SOQL date literals and formatted date values are written without quotes.

What's the difference between LAST_N_DAYS:n and N_DAYS_AGO:n?

LAST_N_DAYS:n gives a rolling range from n days ago through today (and includes today); N_DAYS_AGO:n-style literals for weeks/months/years mark a single window further back rather than a rolling range — check the reference table above for the exact keyword you need.

Why is my date literal rejected on a DateTime field?

Date and DateTime fields need matching formats — a bare date won't satisfy a DateTime field's comparison. This tool outputs both forms so you can grab the one your field actually needs.

Can I use a date literal with BETWEEN?

No — SOQL date literals don't support BETWEEN; use >=/<=, or = for a literal that already represents a range.

Do fiscal-year literals work out of the box?

Only if your org has custom fiscal years configured in Setup — otherwise they resolve against the standard calendar year.

Enjoyed this? Share it with a friend

Email