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
mikkamikka 

Help!! How to compare two date fields

Hi guys, I am trying to compare two date fields in SF schema and is getting a malformed query error. Can anyone help me how to compare this two date fields please??? My SOQL query is like this: Select c.Status, c.SR_Number__c, c.Id, c.Due_Date__c, c.CreatedDate, c.CaseNumber From Case c where CreatedDate = Due_Date__c I just want to compare if the Created Date has the same date (YYYY-MM-DD) with my due date. Your help will be greatly appreciated. Thanks!!!
bob_buzzardbob_buzzard

You can't compare one field with another as part of the where clause.  The right hand side of the expression must be a native value.  Its documented here:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_fieldexpression.htm

 

 

User@SVFUser@SVF

mikka,

 

One way to handle this is to create a formula field which which returns TRUE if the condition satisfies else false. Then in the SOQL, just refer the <Formula Field> = TRUE in the where clause.

mikkamikka

Thanks guys!!! I'll check that one out. I'll also add another trigger to regularly update the boolean comparison since my due date field values always vary whenever updated. Thank you so much again..