+ Start a Discussion
Jeff C.ax327Jeff C.ax327 

Saving and retrieving datetime values through SforceEnterprise API causes time offset

When I try to save a datetime value to Salesforce through the Enterprise API (SforceEnterprise), 4 hours gets subtracted from the time.  When I retrieve a datetime value from Salesforce through the API, 4 hours gets added to the time.  (my timezone is EST)
It seems obvious that this is a timezone issue, and I have tried the following to no avail:
    mySalesforceObject.MyDatetimeField__c = new DateTime(dtmOrigDateTime, DateTimeKind.Utc);
I figured that by specifying that it is a UTC datetime, that would fix it, but it doesn't.
All I want is for the time to be saved and retrieved as is, with no subtraction or addition of hours.
Is there a setting on the sforceService object somewhere or on the SObject that can correct this behavior?
Thank you for your help, this is driving me nuts.
Jeff C.ax327Jeff C.ax327
Alright, I've solved my own problem.  Pretty straightforward really...
When saving to SalesForce, convert the value to Universal time:
   sfObj.MyDateTime__c = dtmMyDateTime.ToUniversalTime();
When retrieving from SalesForce, convert to Local time:

    dtmMyDateTime = ((DateTime)sfObj.MyDateTime__c).ToLocalTime();

I guess I couldn't find the answer anywhere because it is so easy that no one is talking about it online.
I hope that posting the answer here helps someone else trying to figure it out.

Here is what I am doing

format it into "yyyy'-'MM'-'dd'T'HH':'mm':'ss'
writing to a file
then reading the timestamp from file in a string
then adding to a query with where LastModifiedDate >= timestamp

It is not giving the right records because ServerTimeStamp gives the GMT time.
how would I do that.
I get binding.geUserInfo.GetTimeZone();


but how do we convert it to ("yyyy'-'MM'-'dd'T'HH':'mm':'ss'- xx:xx) format