DateTime for Serialization

by matt 28. November 2007 12:31
I have recently been working on a project where I have the following scenario:
  1. Receive a flat file from system X.
  2. Map the flat file to an internal message schema.
  3. Send the mapped message to a web service in system Y.
Three very basic steps, I am sure you will agree.  I did however run in to a problem with date formatting.  I had agreed with the developers of system Y, that thye shold be using System.DateTime for  their dates and not worrying about the format required by system X.  When serializing, this was fine and we got the dates that BizTalk was happy with.

I.e. 2007-10-26T17:54:57.437

Great, I could convert this to the formats i needed for system X in the maps using some custom functiods.  My problem was that in the other direction, it was quite difficult to create a date format as above.  I tried all of the string methods on the System.DateTime class and didn't really get anywhere.  I would get the error "The string '26/10/2007 17:54:57' is not a valid AllXsd value".  Luckily, I happened across this post on The Scripts.

Essentially, what is is saying is that if you use the .ToString() method witha  parameter of "s", then this will format the string according to ISO-8601, which is what the XML Schema Date is based on, and what .Net uses for serialization.

So, using

DateTime.Now.ToString("s");

will result in

2007-11-28T12:22:15.041

Hurrah!

Tags:

ASP.NET | BizTalk Server

Comments

2/13/2009 3:01:35 PM #

Great post!  However, I have a similar problem.  I inherited a cube in which one measure, when dragged into the data area, shows an error message:

"202673-03-23T00:00:00 is not a valid ALLXsd value"

I have searched for any 03/23/xxxx dates and cannot find any.

Do you have any experience with this problem?

Thank you.

PJ |

2/13/2009 3:38:23 PM #

Not really PJ, I just sent you an email.  I'm hoping that '202673' is just a type though Smile

Matt |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar