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
Jerome ScolaJerome Scola 

How to use Date filter to query

select  Name from Opportunity where CloseDate > 2014-11-08T00:00:00Z

When I used this soql to query in the developer console,I got the following  error message:
value of filter criterion for field 'CloseDate' must be of type of date and should not be enclosed in quotes 

I am sure the CloseDate is a Date type. how to correct the query soql to make it work.
Best Answer chosen by Jerome Scola
Sameer Tyagi SFDCSameer Tyagi SFDC
Hi Jerome, 

You are giving date in Datetime format instead of Date format. 

Here is the correct line
select  Name from Opportunity where CloseDate > 2014-11-08


If you want to use it your apex code, it should be like this. 
date dt = date.parse('12/27/2009');
list<opportunity> opplst = [SELECT Id FROM opportunity WHERE closedate > :dt];

Thanks & Regards, 
Sameer Tyagi
http://mirketa.com

 

All Answers

Sameer Tyagi SFDCSameer Tyagi SFDC
Hi Jerome, 

You are giving date in Datetime format instead of Date format. 

Here is the correct line
select  Name from Opportunity where CloseDate > 2014-11-08


If you want to use it your apex code, it should be like this. 
date dt = date.parse('12/27/2009');
list<opportunity> opplst = [SELECT Id FROM opportunity WHERE closedate > :dt];

Thanks & Regards, 
Sameer Tyagi
http://mirketa.com

 
This was selected as the best answer
usha sankausha sanka
how to change the look field to multiselect option in the droup down option we can see'all' it is possible
any one know about send me basic code