Sign up ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I know that you get today's date like this: What would be the best solution to get yesterday's date?

share|improve this question

2 Answers 2

up vote 22 down vote accepted

Just use addDays with a negative value:
share|improve this answer

You can use the addDays() functions as already mentioned, but SOQL has a Date Literal Already set up for this, and might be a bit more simple. You just simply have to query for a date of YESTERDAY

An example

list<Account> accounts = [Select Id From Account Where CreatedDate = YESTERDAY];

Here is the documentation for Date Literals. Although the addDays() works, this seems a bit more clean in some use cases.

share|improve this answer
Isn't this a bad solution? YESTERDAY returns yesterdays date beginning from 12am. You are missing out on all records between 0am and 11:59am. Or did I misunderstand something? – Frederik Witte May 4 at 10:06
Well, if that were teh case then addDays() would be bad as well because they both return yesterday beginning from 12am. 12am is 0000, or 0am as you call it, so there is no issue with missing records created at certain times.… – Chris Duncombe May 4 at 10:46
Ah yeah. Then your solution will work. If you use then you will need the addDays() function. addDays() doesn't return the date from 12am. The "today()" function is the day at 12am. If you use with addDays() then you will have the correct times. – Frederik Witte May 4 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.