2

I am running a SOQL query and getting a date/time field value as per user's timezone. I have a requirement to change the timezone in EST in the SOQL query itself. For example: User is in PST and while running SOQL query I am getting createdDate field value in PST. But I need that the result should give the createdDate value in EST.

Date in PST = SELECT CreatedDate FROM Opportunity
Date in EST = SELECT ????? FROM Opportunity

Thanks.

Dmitriy
  • 5,525
  • 12
  • 25
  • 38
ankit agarwal
  • 21
  • 1
  • 2

1 Answers1

2

From Date Formats and Date Literals

dateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion.

You can use format(dateFormatString, timezone) method of Datetime class or dateGMT() to convert date in Apex.

If you need to display date somewhere outside of Salesforce, you will need to do this on your end.

Andrii Muzychuk
  • 1,151
  • 3
  • 20
  • 28