You need to sign in to do that
Don't have an account?
RDM1961
Compare two date fields in SOQL
I'm trying to do an update in salesforce using Informatica. The source object has multiple date fields which I'm trying to compare to select records. I get a Malformed Query error when attempting to run the update.
The query statement that informatica generates is below.
SOSQL [Select Discharge_Date__c, Implant_Date__c, Patient__c From Implant__c Where ((((Implant_Date__c > Pts_last_fu_date__c) or (Discharge_Date__c > Pts_last_fu_date__c)) and Patient__c = 'a0630000007ewCc')) LIMIT 10]
Any help would be appreciated,
Thanks,
Rick
You can't compare one field against another only against a literal value. To do this, you first need to create a new formula field that calculates the difference between the 2 dates, then you can write a soql query that filters on that date difference formula field value.
All Answers
I think you should use DATEVALUE function around your date column .. something like this..
SOQL
[Select Discharge_Date__c, Implant_Date__c, Patient__c From Implant__c Where ((((DATEVALUE(Implant_Date__c) > DATEVALUE(Pts_last_fu_date__c)) or (DATEVALUE(Discharge_Date__c) > DATEVALUE(Pts_last_fu_date__c))) and Patient__c = 'a0630000007ewCc')) LIMIT 10]
If you face any issue then feel free to reply back if this work the please mark this as solved.
Thank you,
Atul
you can use daysbetween method to compare your date fields :
date startDate = date.newInstance(2008, 1, 1);
date dueDate = date.newInstance(2008, 1, 30);
integer numberDaysDue = startDate.daysBetween(dueDate);
Hope this helps.
You can't compare one field against another only against a literal value. To do this, you first need to create a new formula field that calculates the difference between the 2 dates, then you can write a soql query that filters on that date difference formula field value.
Thanks for all the suggestions. Here's the final resolution in case it may help anyone else.
Case:
Patient tracking application has Last Follow Up Date on patient record. Needs to update a this date field from one of two date fields in a child object (Implant) if greater than current Last Follow Up Date.
Solution:
If(or( isnull(Patient__r.Last_Follow_up_Date__c), Implant_Date__c > Patient__r.Last_Follow_up_Date__c , Discharge_Date__c > Patient__r.Last_Follow_up_Date__c),'True','False')