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
lopezclopezc 

Date Formats in SOQL

Is it possible to do something like:

 

Select Id from Contact where TODAY - Activated_Date_c >= 5

 

I am getting the error unexpected char '-'

Best Answer chosen by Admin (Salesforce Developers) 
lopezclopezc

Ok, from somebody else conversation I found:

 

"SimonF is correct. You cannot compare two fields, we can only compare a field with literal values. One work around is to use a formula field that has subtracted value the two dates, and then compare this to 0 in the query. ... ..."

 

So I can't compare those 2 formulas...

All Answers

Shailesh DeshpandeShailesh Deshpande

Hi,

 

Please go through the following Link:

 

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

 

I hope this solves your problem.

lopezclopezc

No It doesn't, because I need to implement TODAY - Activation_Date__c where Activation_Date__c is a Date

Shailesh DeshpandeShailesh Deshpande

you may change the condition to ,

 

Activated_Date__c < = Last_N_Days:5

lopezclopezc

Why 5?

 

I have the same problem with formula(number). I am trying to compare 2 of them:

 

Select Days_Since_Activated__c,Account.NotDealtDaysFrom_Ref__c, Account.Id

from Contact

where Account.NotDealtDaysFrom_Ref__c <  Days_Since_Activated__c limit 10

 

Account.NotDealtDaysFrom_Ref__c is a Formula(number)

Days_Since_Activated__c is a Formula(Number)

 

but when I run the query it sais: Unexpected token: 'Days_Since_Activated__c'

 

Any ideas?

Shailesh DeshpandeShailesh Deshpande

try this...m not sure though

 

Select Days_Since_Activated__c,Account.NotDealtDaysFrom_R ef__c, Account.Id

from Contact

where Account.NotDealtDaysFrom_Ref__c <:  Days_Since_Activated__c limit 10

lopezclopezc

Days_Since_Activated__c isn't a variable but a field from the Object Contact, so no, it doesn't work.

 

the weird thing is that this other query works:

 

Select Days_Since_Activated__c,Account.NotDealtDaysFrom_R ef__c, Account.Id

from Contact

where Account.NotDealtDaysFrom_Ref__c <  5 limit 10

 

"5" is a number right? so if "Days_Since_Activated__c" is defined as number, why it is not working?

lopezclopezc

Ok, from somebody else conversation I found:

 

"SimonF is correct. You cannot compare two fields, we can only compare a field with literal values. One work around is to use a formula field that has subtracted value the two dates, and then compare this to 0 in the query. ... ..."

 

So I can't compare those 2 formulas...

This was selected as the best answer
Shailesh DeshpandeShailesh Deshpande

gr8..thanks for sharing this...:)