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
NongNong 

SOQL : Compare DateTime field with current date time

Dear All,

 

I have the problem on SOQL to select past Event from below command but it does not compare the time , i tried system.now() but it did not work.

 

Could you please advise .

 

Select ActivityDateTime  From Event where whatid=:tsk.whatid and  
            what.type = 'Account' and ActivityDateTime <> null and    ActivityDateTime >=LAST_N_DAYS:0  

 

Thank you very much in advance for your help.

 

Best Regards

Anong         

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

Try changing your code as below :

 

Event e=[Select ActivityDateTime  From Event where whatid=:tsk.whatid and what.type = 'Account' and ActivityDateTime <> null and    ActivityDateTime <=:system.now()];

All Answers

Pradeep_NavatarPradeep_Navatar

Try changing your code as below :

 

Event e=[Select ActivityDateTime  From Event where whatid=:tsk.whatid and what.type = 'Account' and ActivityDateTime <> null and    ActivityDateTime <=:system.now()];

This was selected as the best answer
NongNong

Dear Pradeep,

 

Thank you so much for your help , it works , i found my mistake is i used 'ActivityDateTime<=system.now()'     not including   ':' before system.now().

 

Could you please advise the link of the SOQL knowledgebase that i can learn in the future as i am the beginer on this.

 

Best Regards

Anong

Karthik TrainingKarthik Training
Hi Nong ,

Please gothrough the Below links for SOQL ,

http://www.sfdc99.com/2013/06/07/example-how-to-write-a-simple-soql-query/
http://www.salesforcegeneral.com/introduction-to-soql/

Please let me know if you need any information.