function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nikvmnikvm 

how to use date in where clause SOQL ?

 

I am not getting the correct way putting date in below SOQL statement 

 

SELECT id, CreatedDate  FROM Sales_Order__c where CreatedDate < 2013-01-11

 

could some one help please 

 

Thanks 

 

error :

INVALID_FIELD:
recordtype__c FROM Sales_Order__c where CreatedDate < 2013-01-11
^
ERROR at Row:1:Column:877
value of filter criterion for field 'CreatedDate' must be of type dateTime and should not be enclosed in quotes

Best Answer chosen by Admin (Salesforce Developers) 
Neetu BansalNeetu Bansal
CreatedDate is a Datetime field, so you could use this in the following way:

SELECT id, CreatedDate FROM Sales_Order__c where CreatedDate < 2013-05-21T00:00:00Z.



Mark as solution if you are able to fix your problem, so it would help others too.



Thanks,

Neetu Bansal

All Answers

Neetu BansalNeetu Bansal
CreatedDate is a Datetime field, so you could use this in the following way:

SELECT id, CreatedDate FROM Sales_Order__c where CreatedDate < 2013-05-21T00:00:00Z.



Mark as solution if you are able to fix your problem, so it would help others too.



Thanks,

Neetu Bansal
This was selected as the best answer
priyanshu nema 2priyanshu nema 2
To filter a SOQL query on a datetime field with a day value, use the DAY_ONLY SOQL operator

SELECT Id FROM Donation_Allocation__c  WHERE DAY_ONLY(CreatedDate) < 2013-01-11