+ Start a Discussion

Error in setting value for DateTime type custom field

I get the following error while update the contact.
        Error:      '2006-09-06' is not a valid value for the type xsd:dateTime
This is happening when we set the value for DateTime type custom field. I am setting value as
                    sContact.RECEIPT_STATE_DATE_02__cSpecified = true;
                    sContact.RECEIPT_STATE_DATE_02__c = DateTime.Now;
Based on one of the replies from this forum I tried the following but gives compilation error.
                    sContact.RECEIPT_STATE_DATE_02__cSpecified = true;
                    sContact.RECEIPT_STATE_DATE_02__c = (System.DateTime)DateTime.Now.ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo);
I am using MS VS 2005. Please let me know how to resove this error.
Mike LeachMike Leach
I use the following DateTime formats with Partner WSDL when setting XML nodes:

For the Salesforce date type:

xmlNode.InnerText = tmpDate.ToUniversalTime().ToString("yyyy-MM-dd");

For the Salesforce datetime type:

xmlNode.InnerText = tmpDate.ToUniversalTime().ToString("s");

Hope this helps.
Thanks. But please note that you are setting directly to xml node, it is a string type. For me I need to set the property of type DateTime in Contact object.
So I cannot use the above code.
FYI, my field defn looks like this
<element name="RECEIPT_STATE_DATE_02__c" nillable="true" minOccurs="0" type="xsd:dateTime" />
and  I am trying to set value for this Contact object (using c#.NET) propery as follows 
sContact.RECEIPT_STATE_DATE_02__c = DateTime.now;
Type of property is DateTime, still I get error when updating Contact.
Mike LeachMike Leach
Was the RECEIPT_STATE_DATE_02__c type recently changed from datetime to date in Salesforce but the code not recompiled to an updated WSDL?

What happens when you regenerate your WSDL at
and rebuild?


   The type has not been changed. It is xsd:datetime only.

   <element name="RECEIPT_STATE_DATE_01__c" nillable="true" minOccurs="0" type="xsd:dateTime" />

   Please let me know if you aware of some other way to set this value using C#.NET 2.0



Mike LeachMike Leach
I've seen this error message before and the cause was a date/datetime type mismatch between the WSDL and Salesforce.

Did regenerating the WSDL and rebuilding the proxy objects help?

Thanks Mike.

I have informed the support team about this issue. They are looking into it.

I will update once I get answer from them.





Hi Jegadish,

Did you find a solution? I have the same exact problem.... unfortunately. From my experience, opening a ticket with salesfoce is not very helpful... I appreciate it very much if you could share your solution.

Thanks in advance,



Message Edited by saritha78 on 11-10-2006 01:22 PM

There are issues with date/dateTImes in .NET, although i've only seen it happen in query, the explanation of the issue i got would indicate that it could affect serialization as well (i.e. in update/create calls). There's details of a workaround and a MSFT hotfix in this post
 I need t odownload the enterprise.wsdl through my c# code. i tried many scenarios but it is going to login page.
please help me how to do it.
i need to download enterprise.wsdl throgh my c# code. please help me to do it. i tried many scenarios but it is redirecting to
login page.