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
ccrawford07ccrawford07 

Comparing datetime fields in SOQL

Hello,

I'm trying to do a query like this:

Code:
SELECT Id, LastModifiedDate, Name, updatedDate__c FROM Account WHERE LastModifiedDate > updatedDate__c

But I get an error:

Code:
ERROR at Row:1:Column:89
unexpected token: updatedDate__c 


How can I do a quick date comparison in SOQL?

Thanks!
SuperfellSuperfell
You can't, as outlined in the SOQL docs, the righthand side of a comparision has to be a literal value.

You can create a formula field that calcs the difference between your 2 dates, and use that in your query instead.
ccrawford07ccrawford07
Ah ha I missed that in the docs. Thanks.