Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


reading date/time from xml


reading date/time from xml

Author
Message
N_Muller
N_Muller
SSC-Enthusiastic
SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)

Group: General Forum Members
Points: 133 Visits: 405
I have an xml with a date/time with offset:

<start>2014-07-01T13:00:00-06:00</start>

I'm reading this through openxml and my server is in CST:

declare @DT datetime2(0)

select @DT = start
from openxml ( @idoc, '/root', 1 )
with ( start datetime2 'start' )

When I query for @DT I get: 2014-07-01 19:00:00, which is the date/time in UTC, because of the 6-hour offset.

My understanding is that the XML is in UTC and the offset is provided to identify the time zone where the data was originated. I need to read the data such that is returns 2014-07-01 13:00:00.

Can someone please explain what is that I'm doing wrong?

Thanks
MMartin1
MMartin1
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1128 Visits: 2015
In


select @DT = start
from openxml ( @idoc, '/root', 1 )
with ( start datetime2 'start' )



Try changing the DATETIME2 portion to DATETIME2(0) to see if keeping the data type consistent helps.

OR In this case since you have the zone where the time is maybe try substituting datetime2 with DATETIMEOFFSET in the code , then in your select cast this to SMALLDATETIME. See if this helps you.

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search