Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud

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);

}

Posted on Saturday, February 24, 2007 8:36 PM BizTalk | Back to top


Comments on this post: Mapping with xsd:DateTime

# re: Mapping with xsd:DateTime
Requesting Gravatar...
if the string was not a valid date then i wanted to return the min date value.
Felicitaciones de Navidad 2016
Frases de Navidad 2016
Left by DIPIKA on Dec 16, 2016 10:06 PM

# re: Mapping with xsd:DateTime
Requesting Gravatar...
NICE POST ADMIN THANKS.
Left by mobdro tv app for pc on May 12, 2017 6:56 PM

# re: Mapping with xsd:DateTime
Requesting Gravatar...
WHAT AN AMAZING POST ADMIN.
mobdro for Windows
xender download app
Left by mobdro tv app for pc on May 12, 2017 6:57 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Stephenson | Powered by: GeeksWithBlogs.net