9

I'm trying to debug a SOQL query in the developer console's query editor. This works

SELECT Site__c, Cluster__c, Date__c, Num_Att_records__c FROM Session__c 
Where Session__c.SiteProgram__r.Name = 'Brattleboro'

I'm having trouble getting the date format right for the following:

SELECT Site__c, Cluster__c, Date__c, Num_Att_records__c FROM Session__c 
Where Session__c.SiteProgram__r.Name = 'Brattleboro' AND Date__c = 2012-11-6

With the date as shown, I get the message "Unknown error parsing query"

If I put the date in quotes, I don't see the the parsing error message, but I get the following message when I press the execute button

"[object Object]: 'Brattleboro' AND Date__c = '2012-11-6' ^ ERROR at Row:1:Column:147 value of filter criterion for field 'Date__c' must be of type date and should not be enclosed in quotes"

I thought it was ok to use YYYY-MM-DD in this context. Do I need to use the full date time format? Or am I bumping into some quirk of the developer console?

4
  • 1
    Is Date__c a Date only field or a DateTime field? For the latter you will want something like SELECT Site__c FROM Session__c Where Date__c = 2012-11-6T00:00:00Z. See Date Formats and Date Literals Commented Apr 8, 2014 at 21:58
  • When I tried a datetime field with a date constant the message changed to "must be of type dateTime and should not be enclosed in quotes". Without quotes is the way to go but as to why the "Unknown error parsing query" I don't know.
    – Keith C
    Commented Apr 8, 2014 at 22:05
  • It's a Date only field.
    – Jagular
    Commented Apr 8, 2014 at 22:08
  • Fyi a missing = or == in the date test gives and "Unknown error parsing query".
    – Keith C
    Commented Apr 8, 2014 at 22:11

1 Answer 1

14

Try:

SELECT Site__c, Cluster__c, Date__c, Num_Att_records__c 
FROM Session__c  
Where Session__c.SiteProgram__r.Name = 'Brattleboro' AND Date__c = 2012-11-06

Note the leading 0 on the 06.

The format is YYYY-MM-DD, so you need to pad the extra 0.

1
  • 1
    Seems like an easy enough thing to miss. Took me a bit of trial and error to spot the missing 0. Commented Apr 8, 2014 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .