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

567 views Asked by At

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?

1

There are 1 answers

0
DTRT On

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.