2

So it appears that when returning a DATE field from the REST API, that salesforce does NOT convert it to UTC (Doesn't return any time-zone information, just a YYYY-MM-DD string.

Instead it returns the literal value of whatever was entered when saving the record.

These creates quite a challenge if you are trying to display dates in the user local time as you basically need to know what the timezone the date was created in...

I believe this would either be the Company Default Date or the Users Default date.

1: Which is it? 2: How do you retrieve this information? If even possible, I assume it would require an additional query?

  • 1
    It should be in GMT. Maybe share some code? Perhaps it's your code library that's screwing you up? – sfdcfox Jul 26 '18 at 19:48
  • @sfdcfox While DATETIME is in fact returned in UTC, I'm looking at the raw network traffic and DATE fields don't return ANY timestamp information. EG: you just get "My_Date__c": "2019-03-01",. I'm just using the /services/data/v42.0/query?q= endpoint – NSjonas Jul 26 '18 at 21:22
  • I guess maybe timezones don't make sense in the context of dates? I'm trying to think through the use cases (this is for a typescript ORM library so I'm trying to do what makes the most sense universally). If you just run let d = new Date(sob.My_Date_Field__c) it treats the date as if its UTC T00:00. I'm thinking the solution must be to just construct the date ALWAY as exactly what is returned by salesforce. Timezones are always a bit of a head-spin for me – NSjonas Jul 26 '18 at 21:25
2

Dates don't have timezones, and YYYY-MM-dd is the standard (ISO-8601) format for storing them.

The timezone of the user whose storing or retrieving the date shouldn't change the date value.

If timezone actually comes into play you probably should have used date times, i.e. if your calendar is I'm OOO July 1st, 2018 and I'm in EST, that would really mean OOO from July 1st 12am to July 1st 11:59:59:9999 PM

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.