10

There is a Date Field whose value is I gave as 15th Oct 2014. When I insert the same, Is this an absolute time value irrespective of any Time-Zone; does it matter who inserted the Date field? I have user X from timezone: GMT 05:30 and another user Y from timezone: GMT -8:00. We both insert two records of an SObject called 'DateObject' that has a Date field called datefield__c. Does it store differently if X wrote this statements instead of Y?

Date myDate = Date.valueOf('2012-12-25 00:00:00');
insert myDate;

Please clarify. Thanks

10

I know this question is very old, but it comes up as one of the top results on google for Salesforce date timezone questions.

DateTime fields store the time information in UTC and display the appropriate date and time to the user based on the user's personal timezone settings.

Date fields contain no time information and completely ignore timezones. Whatever date you specify when you set it will be the date every user sees, with any time and zone information being ignored.

| improve this answer | |
  • I'm finding this to be true in the REST api. I've a try to parse a date directly with javascript, it returns the wrong day because I'm in MST and javascript expects it to be UTC. This seems to be the correct answer – NSjonas Jul 26 '18 at 19:17
8

SF stores all DateTimes in UTC. Some Native applications handle this conversion for you, but there are use cases where you have to handle the conversion yourself. From the documentation...

Remember that dateTime field values are stored as Coordinated Universal Time (UTC). When one of these values is returned in the Salesforce application, it is automatically adjusted for the timezone specified in your organization preferences. Your application may need to handle this conversion.

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm

As to point out every single use case where you would have to handle this conversion, I do not know. I know that personally, I have run across it when trying to use DateTime fields in Formulas. I had to handle the conversion to my TimeZone myself.

Here is a SFSE question in which I show this actually. This is not meant to help answer the question, but just to give you an idea of a use case where I had to handle the conversion myself.

Case Report grouped by Hour of Day

| improve this answer | |
  • 1
    Is this the same for Date field ? Can you list few scenarios where we need to handle this conversion ? – Venkataraman Mar 19 '15 at 8:26
  • Link appears to not point directly to the reference – Brad Thomas Sep 16 '16 at 19:54
4

Apart from how the dates are stored in the database, this is how I always understood how datetimes / timezones work in Salesforce:

Scenario: entering the "same" datetime in a field by users with different timezones

  • when a user fills a datetime field of 4 PM, this means he is entering the datetime as 4 PM in HIS timezone (GMT 05:30) . The system then will indeed store this as to what that datetime corresponds to in UTC

  • when a user would fill a datetime field with 4 PM, but his user has a different timezone - let's say GMT 02:00, then offcourse, the value stored in the database will NOT be the same as from the first user. This is normal as this second user is living and thinking in the GMT 02:00 timezone and not in the GMT 05:30 timezone... Again here, Salesforce will then convert the 4 PM GMT 02:00 to UTC.

So if you had your users entering datetime information and then you noticed that your users had incorrect settings for their timezone, the datetime values stored in the database will be wrong.

| improve this answer | |
  • Nice way to explain this. – Saariko Sep 14 at 9:17

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.