+ Start a Discussion

Clarification about Timezone Conversion in DateTime

There are lots of posts regarding DateTime format. But I have things that I still can't find a solid answer for.

1). I Noticed that datetime field values are converted into UTC and that converted values will be kept in the back-end. When rendering those values in the UI, again it will be converted into the Organization/User's timezone.
2). Only the values which are coming directly from the UI(user entered) will be converted or any datetime field value(such as updating through controllers or triggers) will be converted?
3). In SOQL WHERE clauses, what is the best way to use DateTime fields to avoid potential confusing search results?

I recently noticed this behavior in salesforce and managed to resolve the difficulties. But I really need to get understand clearly the ins-and-outs as a developer :).
Below are the assumptions for each of above that I have taken based on my understanding up to now.
1). Yes
2). All the fields will be converted. No matter whether the value has been set by DateTime.parse(string) or DateTime.valueof(string) or whatever
3). Hope DATE_TIME_FORMAULA(convertTimeZone(*dateTime*)) = myValue will help here. Until now I've been able to manage with Date fields since there was no need to filter based on time.

Also the datetime fields those are retrieved via REST API will have GMT values or converted values?
Scott McClungScott McClung
Hi Madhura,
1. Yes, you are correct.
2. The date and datetime fields are always converted to the local timezone of the context user.  Unless you specifically use the GMT methods.   https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm
3. Sorry, I'm not following what this question is....
4. The API sends the datetime fields in UTC.  Timezone management has to be handled in the client application.