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
Vivek NayakVivek Nayak 

Urgent: Need to pass dynamic date to datetime field in SOQL

Hi folks,
I am struglling to compare one datetime field to dynamic date in SOQL.
Below is my query:

Select Id from Customobject__c where
EndDate__c =datetime.now().addMonths(3);

now problem is EndDate__c format on existing records which is
2020-08-28T14:00:00.000+0000

and i have compare this format with a date 3 month after today.
i.e. datetime.now().addMonths(3) or date.today.addMonths(3) whose value  will be
2020-09-02 00:00:00. 

I cant change EndDate__c format so how do i adjust RHS fomat (datetime) similar to EndDate__c   so that it can be compare to fecth records.
also tried 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'' but still no chance.
Any help would be really help 
Thanks
 

 
David Zhu 🔥David Zhu 🔥
You may try:

datetime dt =datetime.now().addMonths(3);
List<Customobject__c > Customobjects= [Select Id from Customobject__c where EndDate__c  =:dt];