+ Start a Discussion
RussYoungRussYoung 

.net 4 DateTime weirdness.

I'm new to the salesforce api and having a problem creating a new Case.

 

WSDL: Enterprise
.Net: 4.0
TimeZone in Salesforce: (GMT-07:00) Mountain Standard Time
TimeZone on computer: (UTC-07:00) Mountain Time (US & Canada)

 

I have a custom DateTime field "BillNext__c" defined in Cases

 

Here's the c# code snippet:

 

DateTime sfDateTime = DateTime.Now;
string updateValue = "2013-01-21 06:00:00";
parseOK = DateTime.TryParse(updateValue, out sfDateTime);

 

 

At this point sfDateTime is a date that looks like this: 21-Jan-13 6:00:00AM

 

I then set the "BillNext__c" property to "sfDateTime" and then set the "BillNext__cSpecified" property to true

 

The case gets added, but the BillNext in the user interface shows "1/10/2013 11:00 PM"

 

Any insights would be appreciated.

 

Thanks,

 

Russ

_Prasu__Prasu_

Did you tried to convert time to GMT or UTC before adding to Salesforce?

JWykelJWykel
SF stores datetimes in UTC. .Net will convert that string to local time. Setting BillNext__c to it will transfer the local time across and SF will store it as though it is UTC, giving you a different time/date based on your computer's timezone compared to UTC.

There should never be a reason for it to change it to 10 days difference, though...something else is wrong with that.

If you want to set BillNext__c to 6am on January 21st, you should be able to do this:
obj.BillNext__c = DateTime.Parse("2013-01-21 06:00:00").ToUniversalTime();
sfdc.update(new sObject[]{ obj });