Search code examples
dateselectcomparisonsalesforcesoql

SOQL date comparison for formula(date) date type


can anybody help me with writing a SOQL query. Using "Date" data type in WHERE statement is easy, it behaves like a normal Date would. But if the data type is "Formula(Date)" it seems like normal date time functions are not working. In sample query like

SELECT Date_of_purchase__c FROM Goods WHERE Date_of_purchase__c = 2011-11-04

all works fine if "Date_of_purchase__c" field is "Date" type. But the same query fails if the field type is "Formula(Date)". What am I doing wrong? Thanks!


Solution

  • Are you 100% sure your formula is using the date type and not datetime? I just created a formula field on Contact to test, using the formula:

    DATEVALUE(CreatedDate)
    

    I then ran the following code in the system log:

    System.Debug([Select Name From Contact Where CreatedDateF__c = 2011-12-16]);
    

    and I can see that it returned 20 rows.