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
npaustiannpaustian 

Token Error on SOQL WHERE CLAUSE

Hi, 

 

I'm getting this error - can anyone help me tp understand whay this simple SELEST QUERY doesn't work?

 

Query in Forice.Com Explorer:

SELECT Id FROM Account WHERE DateDiff(day, CreatedDate, GETDATE()) = 0

 

It return the follwing error:

MALFORMED_QUERY:
FROM Account WHERE DateDiff(day, CreatedDate, GETDATE()) = 0
^
ERROR at Row:1:Column:41
unexpected token: ','

 

Best regards,

Nicolai

Best Answer chosen by Admin (Salesforce Developers) 
PrakashbPrakashb

Hi,

 

You cannot use the DATEDIFF method in SOQL.

 

You can odify your query to

 

Date todaydate = System.today();

SELECT Id FROM Account WHERE CreatedDate =: todaydate;

 

This would give you all the accounts created taody, which i think is what you are trying to get.

All Answers

PrakashbPrakashb

Hi,

 

You cannot use the DATEDIFF method in SOQL.

 

You can odify your query to

 

Date todaydate = System.today();

SELECT Id FROM Account WHERE CreatedDate =: todaydate;

 

This would give you all the accounts created taody, which i think is what you are trying to get.

This was selected as the best answer
bvramkumarbvramkumar

you can do this too. no need of that extra variable.

 

List<Account> lst = [SELECT Id FROM Account WHERE CreatedDate = :system.today()];

 

and if you want this in Force.Com explorer... below would be perfect.

 

SELECT Id FROM Account WHERE CreatedDate = TODAY

 

TODAY here is a Date literal. See the documentation here.