Salesforce Developer Soql Date Time


// Salesforce - Developer - SOQL - Date and Datetime

We can use date or datetime values, or date literals.  The format for date and 
datetime fields are different.

In a SOQL query, we can specify either a particular date or date literal.  A 
date literal is a fixed expression that represents a relative range of time, 
such as last month, this week, or next year.

Salesforce stores dateTime values as UTC.  When a dateTime value is returned in 
Salesforce, it's adjusted for the time zone specified in our org preferences.  
SOQL queries, however, return dateTime values as UTC values.  If we want to 
process these values in different time zones, our application may need to handle 
the conversion.

Do not use quotes around the date.

SELECT NAME FROM ACCOUNT WHERE CreateDate > 2011-04-26T10:00:00-08:00;
SELECT Amount FROM Opportunity WHERE CALENDAR_YEAR(CreateDate) = 2001;

Salesforce supports a large number of date literals such as YESTERDAY, TODAY, 
TOMORROW, LAST_WEEK, NEXT_90_DAYS, NEXT_YEAR, etc..  See the SOQL Developer 
Guide for the complete list.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License