Search code examples
c#biztalkbiztalk-2013

Is there a Datetime format which not change the output date value?


I have a string in an XML which is a datetime with a timezone and I would like to change it to a DateTime format in C#.

The problem is that it go from the string format to datetime format, the value change due to the timezone.

So I would like to know how to change the xml string to c# datetime without the modification of the value.

The string xml value is :

2014-01-01T00:00:00.0000000+02:00

and when I apply the datetime format it goes to :

12/31/2013 10:00:00 PM

Here is my c# code to convert string to datetime :

Convert.ToDateTime(datestringXml);

I need to sort the date with the Max() and Min() function

I expect the output to be 01/01/2014... (I don't care about the hours, minutes and seconds)


Solution

  • You're using a DateTime object instead of a DateTimeOffset object. The offset part +02:00 doesn't fit in a DateTime object so it calculates the DateTime for you. You wouldn't have this issue if you'd just parse the value into a DateTimeOffset object.