function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmxintcmxint 

Date/Time field adjustments

Hi guys!

My problem is in handling date/time field. There is a custom table with custom date/time field in it. This field is a primary key (logical) of table. I need to insert values into that field. When I'm trying to insert value it is inserted with time shifting regarding my timezone and timezone setup on SDFC settings. I have GMT+02:00 tz and SFDC has GMT-05:00 tz. So these seven hours are subtracted from value that is inserted into table. After investigating sforce forums I've realized that I need to add these seven hours to value before insert. I can get my timeshift (+02:00), but how can I get what time shift does SFDC Org has (in example it -05:00)???

When I'm trying to call getServerTimestamp() I get server timestamp converted to my local time. Even if I'll convert this value into UTC format I will be unable to get time shift of Org settings (-05:00) which I need to find out how many hours should I add to date/time value before insert.

May be someone has already found solution for this issue???

Any advices/comments/links appreciated.

SuperfellSuperfell
I'm not sure the tz of the org has any affect on the API, all date/times are normalized to UTC in the DB and all date/times on the wire include the timezone offset that's been applied (in .NET these date/times are automatically converted to local time of your machine because the DateTime type in .NET has no concept of a timezone).

So, if you send up 2004-11-30T13:00:00+2:00 (1 PM in your TZ), we'll store
2004-11-30T11:00:00Z (11 AM in UTC, the same point in time). If you query this back through the API you'll get 2004-11-30T11:00:00Z on the wire, and .NET will convert this back to your local time, so your DateTime object will say 2004-11-30T13:00:00. If you look at this in the App, you should get 2004-11-30 6:00 AM (if your TZ in the App is -5:00) Those 3 date/times all referer to the same point in time.

What it sounds like is that you're in +2:00, but you have some DateTime's (from a DB or whatever) that are in -05:00. You'll need to apply the correction to the real local time before calling the API. That offset is everything to do with your data source, and nothing to do with the salesforce.com config.

Hope that's clear (TZ stuff is messy).