I am writing a SOQL query in Apex like:

Select Id From Case Where Day_Only(Date_Time_Order_Received__c) >= :startDate

But it seems to me that the Day_Only function will calculate the datetime field based on GMT time. Is there a way to use log in user's time instead of GMT time?


SOQL has a function called convertTimezone() that you can use in other date functions to return the value converted to the user's timezone:

Select Id From Case 
Where Day_Only(convertTimezone(Date_Time_Order_Received__c)) >= :startDate

Converting Time Zones in Date Functions

For Info:

SOQL queries in a client application return dateTime field values as Coordinated Universal Time (UTC) values. You can use convertTimezone() in a date function to convert dateTime fields to the user’s time zone.

  • I there a page in the SFDC docs where we can find all the functions available in SOQL ?, cause I am discovering the existence of new function supported in SOQL every week :p – benahm Mar 24 '17 at 15:38
  • 1
    The Force.com SOQL and SOSL Reference is the primary reference. Definitely worth reading. – martin Mar 24 '17 at 15:47
  • @benahm Salesforce is very well documented and the developer guides are quite good for SOQL and SOSL, SOAP API, Metadata API, Tooling API, and so on. – Adrian Larson Mar 24 '17 at 17:24
  • @AdrianLarson In the case of APIs it's OK but in case of SOQL I dont find that well documented, example I've tried a group by in a where subquery got error parse, but when I check the doc => developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/… nothing tells me that is not supported in that case .... – benahm Mar 24 '17 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.