Michael Stephenson

keeping your feet on premise while your heads in the cloud
posts - 310 , comments - 350 , trackbacks - 11

My Links

News

View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn

Twitter












Archives

Post Categories

Image Galleries

BizTalk

Mates

Mapping with xsd:DateTime

Problem

I was wanting to take a string and map it to a date, if the string was not a valid date then i wanted to return the min date value.  i had this seemingly working okay but the problem was i was getting an error that the date was not a compatible xsd date. 

Solution

Im sure there will be other ways of doing this, but i found a handle little class in the System.Runtime.Remoting.Metadata.W3cXsd2001 namespace called SoapDateTime.  Basically it has a handly static method of ToString which will take a .net DateTime and return an xsd compatible date time string.  There is a code snippet below.

public string ConvertWithDefaultMin(string inputDate)

{

         DateTime requiredDate;

         bool parsed = DateTime.TryParse(inputDate, out requiredDate);

         if (!parsed)

         {

                  string message = string.Format(CultureInfo.InvariantCulture, "The input date string {0} could not be parsed", inputDate);

                  InstrumentationHelper.LogWarning(EventNumbers.DateTimeFormatterCanNotParseDate, Constants.ApplicationName, message);

         }

         return SoapDateTime.ToString(requiredDate);

}

Print | posted on Saturday, February 24, 2007 8:36 PM | Filed Under [ BizTalk ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: