SOQL Query for Users Created in the Last 30 Days
SOQL for users created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
Updated 2026-09-09
Date-literal filters are the difference between a query you rewrite every month and one you save once. This page covers the user version and the literals worth memorising.
User queries are the fastest way to audit licences, dormant logins, and profile assignments without opening Setup.
The query
LAST_N_DAYS:30 is evaluated against the running user's time zone, so the same saved query keeps working tomorrow.
SELECT Id, Name, Username, Email
FROM User
WHERE CreatedDate = LAST_N_DAYS:30
ORDER BY CreatedDate DESC
LIMIT 200Other date literals that work here
SELECT Id, Name, Username, Email
FROM User
WHERE CreatedDate = THIS_MONTH
ORDER BY CreatedDate DESCTODAY,YESTERDAY,THIS_WEEK,THIS_MONTH,THIS_QUARTER,THIS_YEARLAST_N_DAYS:n,NEXT_N_DAYS:n,LAST_N_MONTHS:n- An explicit range:
CreatedDate >= 2026-01-01T00:00:00Z AND CreatedDate < 2026-02-01T00:00:00Z
Filter on LastLoginDate instead
CreatedDate tells you when the record entered Salesforce. For users, LastLoginDate is usually the date the business actually cares about.
SELECT Id, Name, Username, Email
FROM User
WHERE LastLoginDate = LAST_N_DAYS:30
ORDER BY LastLoginDate DESCCommon mistakes to avoid
- Use the API name
User, not the UI label - the two differ on several standard objects. - Wrap literal text values in single quotes; date literals such as
LAST_N_DAYS:30must stay unquoted. - Run the query in a sandbox first if it feeds a bulk update - a
WHEREclause that is one character off can select the whole table. - Date literals are never quoted.
WHERE CreatedDate = 'LAST_N_DAYS:30'fails with a malformed-query error. CreatedDateis a dateTime; comparing it to a plain2026-01-01date value silently shifts the boundary by your time-zone offset.
Run it faster with TurboKit
Recency filters are the most re-run queries an admin owns, which is why saving and re-running them matters more than writing them once.
TurboKit's AI SOQL builder lets you describe the result you want in plain English, returns the query, and exports the rows to CSV or Excel in the same panel - without leaving the Salesforce tab you are already on.
Frequently asked questions
- Is LAST_N_DAYS:30 the same as the last calendar month?
- No.
LAST_N_DAYS:30is a rolling 30-day window ending today, and it excludes today's records in some contexts.LAST_MONTHis the previous calendar month. - Can I filter User on a custom date field the same way?
- Yes. Date literals work on any Date or DateTime field, standard or custom - just use the field's API name, including the
__csuffix. - Why do I get records outside my window?
- Date literals resolve in the running user's time zone. If your user's locale differs from the org default, the boundaries move by the offset between them.
More from the SOQL Library
- SOQL GROUP BY: Users by ProfileIdAggregate SOQL that breaks users down by ProfileId, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query for Accounts Created in the Last 30 DaysSOQL for accounts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Campaigns Created in the Last 30 DaysSOQL for campaigns created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Cases Created in the Last 30 DaysSOQL for cases created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Contacts Created in the Last 30 DaysSOQL for contacts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Leads Created in the Last 30 DaysSOQL for leads created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
Related reading
- Admin How-ToHow to Write Salesforce Queries Without Knowing SOQL (AI SOQL)Describe the records you want in plain English and get a runnable SOQL query back - how AI SOQL builders work, what to check before you run the result, and where they still fall short.
- GlossaryWhat Is an AI SOQL Builder in Salesforce?An AI SOQL builder turns a plain-English description of the records you want into a runnable SOQL query, using the schema of the org you are working in so the