Does LAST_N_DAYS:1 Include TODAY?
In contradiction to what the current documentation claims, you can observe that the LAST_N_DAYS
date literal includes today's data.
To be sure, I ran this query:
SELECT CreatedDate FROM MyObject__c
WHERE CreatedDate = LAST_N_DAYS:1
ORDER BY CreatedDate DESC LIMIT 1
And I got back:
2017-08-31T18:16:17.000+0000
I used the following in my WHERE
clause, and it works as a replacement that operates the same as LAST_N_DAYS
is documented as expecting to work.
SELECT Id
FROM MyObject__c
WHERE CreatedDate = LAST_N_DAYS:n AND CreatedDate < TODAY
Explanation: TODAY
represents a range that "Starts 00:00:00 of the current day and continues for 24 hours." LAST_N_DAYS:n
is supposed to represent a range that, "starts 00:00:00 of the current day and continues for the past n days," but in practice, appears to be the expected range union TODAY
. Thus, by removing anything that is in the TODAY
range, we have the expected range.