简体   繁体   中英

How to set .NET's DateTime value to XML's date field with BizTalk mapping?

I have a Script functoid into my BizTalk mapping, which uses C# and creates DateTime value, which I want to set to "date" field of result schema. This field has type "xs:date"

Functoid's code:

public DateTime GetValue()
{
    string[] dateArray = "2017-06-19".Split('-');
    DateTime result = new DateTime(int.Parse(dateArray[0]), int.Parse(dateArray[1]), int.Parse(dateArray[2]));
    return result;
}

When I test a map, I get an error

"The 'date' element is invalid - The value '2017-06-19T00:00:00' is invalid according to its datatype ' http://www.w3.org/2001/XMLSchema:date ' - The string '2017-06-19T00:00:00' is not a valid Date value."

How can I solve this problem?

Your process is not correct. But it's very easy to resolve.

You need to use TryParseExact() to convert from the string format to a valid DataTime instance.

Then, you use ToString() with the "o" Format String to emit a xs:date compatible string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM