You need to sign in to do that
Don't have an account?

Filter soql queries based on dates
I am trying to write a soql query to return objects based on a datetime field on the object. When I try to use any of the comparison operators on the datetimes ( <, = ) I get the error "No viable alternative at character ' ' " which is ever so helpful in usual salesforce style. The error points at the comparison operator. How can I compare dates in a soql query?
When writing a SOQL query, the Date/Time field has to be in the format:
YYYY-MM-DDTHH:mm:SS.sssZ
Note that the time is based on GMT, so you'll have to do the conversion.
For example, say you want to return Leads whose last modified date is greater than 9/1/2009 at 10:00AM EST, You would use the following:
Select Id, FirstName, LastName from Lead where LastModifiedDate > 2009-09-01T14:00:00.000Z
(Assuming I got the conversion correct) :smileyvery-happy:
this helped me ./.../thank u so much
Hi All
I am experiencing a similar kind of problem. I have a date field coming from VF page and I am preparing a query with where clause as:
select testfield from testobject where testfield=:myDateField
I am getting exception in debug logs as:
no viable alternative at character ' '
I looked into DateTime class as well but didn't find any resolution to this. Please suggest.
TIA.
Regards
Sachin
Further to this:
My debug logs are showing date as: 1765-09-09 00:00:00 ('T' and 'Z') characters missing. May be this is causing problem.
Any suggestions.
Regards
Sachin