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
wixxeywixxey 

Date Comparision in SOQL

Hey!

 

I have the following SOQL

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
        soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\')';

 in the Nested SOQL the table LocationAssesmentRelationShip__c has an expiryDate__c column, i want to check whether the ExpiryDate is greater then the Date.today().

Kindly help if possible

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You should just be able to use the TODAY literal:

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
        soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\' and ExpiryDate__c>TODAY');

 There's more information on the literals at:

 

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

All Answers

bob_buzzardbob_buzzard

You should just be able to use the TODAY literal:

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
        soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\' and ExpiryDate__c>TODAY');

 There's more information on the literals at:

 

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

This was selected as the best answer
Puja_mfsiPuja_mfsi

Hi,

You need to declare a date variable which store the today value.

Date todayDate = System.Today();

and put in your code.

 

soql = 'select Id, Name, Price__c, Test_Name__c, Analyte__c , Manufacturer__c, Device__c, URL__c From Assessment__c where ';
soql = soql+ 'Id NOT IN (Select Assessment__c From LocationAssesmentRelationship__c where Location__c = \''+ locationId +'\'';

soql +=' and expiryDate__c >:todayDate ) ';

 

Where 'todayDate' is a public variable.

 

 

 

wixxeywixxey
thanx Bob this works for me........