Apex: getting yesterday's date

Just use addDays with a negative value:

Date.today().addDays(-1)

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.

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm


This also works

System.today() - 1

Tags:

Date

Soql

Apex