[SalesForce] Day_Only in SOQL considering timezone

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?

Best Answer

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.

Related Topic