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
Vishnu_SFDCVishnu_SFDC 

How to compare date with another custom date in an SOQL query

Hello,

Below is the requirment.

I have to get all records which are greater than a custom date(which is calculated in apex class).

example:

list<event__c> e = [select Id,Start_Datetime__c From event__c Where Start_Datetime__c > "Custom date" ];

Thanks,
Vishnu
Shingo YamazakiShingo Yamazaki
Hello, Vishnu.

I'm Shingo Yamazaki, a Japanese Developer.

How about trying like this?
(add colon (":") to variable you declared in your Apex.)
// custom date value
Date myDate = Date.today();

List<event__c> = [SELECT Id,Start_Datetime__c From event__c Where Start_Datetime__c > :myDate ];
Please be careful that if data type of your custom field "Start_Datetime__c" is "Datetime", 
you probably have to use "Datetime" type variable to compare.

Regards,
Shingo.
 

Ramu_SFDCRamu_SFDC
It is also best that you go through the below articles

http://mysalesforcecode.blogspot.sg/2009/02/date-formats-and-date-literals-in-soql.html

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm