BizTalk Server Orchestration - Conversion from xs:string to xs:dateTime

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server Orchestration > December 2005 > Conversion from xs:string to xs:dateTime





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Conversion from xs:string to xs:dateTime
Theo

2005-12-22, 7:48 am

Hi!

I have problems in converting a simple xs:string containing a correctly
formatted date to xs:dateTime variable. My origin schema uses strings for
dates but my destination schema uses the variable xs:datetime. I'm trying to
convert this string within a scripting fuctoid using the function
System.Convert.ToDateTime(). Unfortunatelly it doesn't seem to work. I'm
getting an exception sayin "Object type cannot be converted to target type".

How can I convert xs:string to xs:dateTime??

thanks!
Samuel L

2005-12-22, 7:48 am

Hi Theo!

Here is a suggestion. It will either work or not depending on how the source
date is formatted. If the source date is formatted like "2005-12-24 15:00"
then the following inline c# code should work:

public string ConvertToDate(string d)
{
System.DateTime temp = System.DateTime.Parse(d);
return temp.ToShortDateString() + "T" + temp.TimeOfDay;
}

Hope this helps you in some way!
Please let me know whether it worked or not.
Good luck!


"Theo" wrote:

> Hi!
>
> I have problems in converting a simple xs:string containing a correctly
> formatted date to xs:dateTime variable. My origin schema uses strings for
> dates but my destination schema uses the variable xs:datetime. I'm trying to
> convert this string within a scripting fuctoid using the function
> System.Convert.ToDateTime(). Unfortunatelly it doesn't seem to work. I'm
> getting an exception sayin "Object type cannot be converted to target type".
>
> How can I convert xs:string to xs:dateTime??
>
> thanks!

Theo

2005-12-22, 7:48 am

Hi!

Thanks for your answer but unfortunatelly it doesn't work. System.DateTime
and xs:dateTime apparently don't match.

//theo

"Samuel L" wrote:
[vbcol=seagreen]
> Hi Theo!
>
> Here is a suggestion. It will either work or not depending on how the source
> date is formatted. If the source date is formatted like "2005-12-24 15:00"
> then the following inline c# code should work:
>
> public string ConvertToDate(string d)
> {
> System.DateTime temp = System.DateTime.Parse(d);
> return temp.ToShortDateString() + "T" + temp.TimeOfDay;
> }
>
> Hope this helps you in some way!
> Please let me know whether it worked or not.
> Good luck!
>
>
> "Theo" wrote:
>
Samuel L

2005-12-22, 7:48 am

Hrm... No that's right. But that's the function puts the character T between
the date and the time, for the date to adapt the xs:dateTime format.

What more exactly does your schemas look like?

I tested this using a map from a source document like this (where the Date
node has type xs:string):
<ns0:DateSource xmlns:ns0="http://TestMapping.DateSource">
<Date>2005-12-24 15:00</Date>
</ns0:DateSource>

And it ouput this (where the date node has type xs:dateTime):
<ns0:DateDest xmlns:ns0="http://TestMapping.DateDest">
<Date>1999-12-24T12:34:00</Date>
</ns0:DateDest>

This instance is accepted by the schema validation, hence the xs:dateTime is
accepted as well.

But exactly does your error tell you?
Have you tested my c# funciton using the 'Test map' feature?



"Theo" wrote:
[vbcol=seagreen]
> Hi!
>
> Thanks for your answer but unfortunatelly it doesn't work. System.DateTime
> and xs:dateTime apparently don't match.
>
> //theo
>
> "Samuel L" wrote:
>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com