Hello all,
I have an incoming XML file that contains a date field in dateTime format as follows: yyyy-MM-ddThh:mm:ss
The outbound file that I need to populate from this incoming file has to have this particular date in the format MM/dd/yy.
To do this I am using an inline C# scripting functoid in a BizTalk Map.
The source schema has the original yyyy-MM-ddThh:mm:ss format stored as an xs:string. The destination schema needs it as an xs:date in the format MM/dd/yy as I mentioned previously.
The C# code I am using to accomplish this conversion is as follows:
public string dateConversion(string currDate) { DateTime d = DateTime.Parse(currDate); string convertedDate; convertedDate = d.ToString("MM/dd/yy"); return convertedDate; }
I have done this before in scenarios that are exactly the same using this bit of code and it's worked flawlessly. However, in this particular instance it is throwing an exception error when I try to test the map against the XML source file.
Here is the error log:
XSL transform error: Function 'userCSharp:dateConversion()' has failed. Exception has been thrown by the target of an invocation. String was not recognized as a valid DateTime.
I've tried changing the data type in the source schema to both xs:date and xs:dateTime but it's always the same error and I can't figure it out.
Any help would be greatly appreciated.
Do onething.
You got your Schema which conatins the field element as date or datetime.
Right click the file in VS and generate an instance of it.
That field will have the value in some date time format.....try matching your incoming value with this format.
Regards,NISHIL MCT,MCTS | Freelance BizTalk Consultant.biztalkconnect.blogspot.com
Try this:
DateTime s1= DateTime.ParseExact(Date1,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture);
string datefin = s1.ToString("yyyy-MM-dd");
return datefin;
public string dateConversion(string currDate)
{
System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InvariantCulture;
DateTime convertedDate = System.DateTime.ParseExact(currDate, "yyyyMMdd", ci);
return convertedDate.ToString("yyyy-MM-dd", ci);
}