How to query DateTime field in Salesforce?

How to query DateTime field in Salesforce?

Salesforce stores the DateTime in GMT/UTC.

Below SOQL will give the number of accounts that were created between 5 PM to 5.15 PM EST.

Since EST is +5 from GMT, 12 + 5 + 5 = 22 is used in the query.

Sample SOQL:

SELECT COUNT( Id ) FROM Account 
WHERE CreatedDate >= 2019-03-04T22:00:00Z AND CreatedDate <= 2019-03-04T22:15:00Z

Output:

Sample Query:

SELECT Id, LastModifiedDate, SystemModStamp  
FROM Account 
WHERE SystemModStamp = TODAY ORDER BY SystemModStamp DESC LIMIT 5

Leave a Reply