Using a date for a datetime field in a SOQL Query [duplicate]

The SF doc explains how to put a Datetime query in a SOQL query.

SELECT Id
FROM Account
WHERE CreatedDate > 2005-10-08T01:02:03Z

I need to just put in a date for this query. Something like:

SELECT Id
FROM Account
WHERE CreatedDate > 2005-10-08

But that throws an error. Any ideas?

Answer

CreatedDate is a datetime field so I guess you would need to specify the time component.

Can you do something like where you just append the time portion to be 12 am by default.

WHERE CreatedDate > 2005-10-08T00:00:00Z

Or you can use Date Literals like

 WHERE CreatedDate > YESTERDAY

For more on date formats and more literal values see,

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

Attribution
Source : Link , Question Author : dublintech , Answer Author : ahiijny

Leave a Comment