Return to Snippet

Revision: 3916
at October 3, 2007 17:51 by rengber

Initial Code
declare @stringDate varchar(30);
declare @myXmlDate xml
declare @serializedDate datetime
declare @xQuery varchar(100)
set @stringDate = '2007-10-03T11:24:07.003+12:00'
set @myXmlDate = cast('' as xml) --Gets an empty Xml datatype
set @serializedDate = @myXmlDate.value('xs:dateTime(sql:variable("@stringDate"))', 'datetime')
select @serializedDate

Initial URL

Initial Description
This is as small as this can go: 
It needs to be a literal string for the Value() function.  

Xml Datatype

Sql:Variable() Function

'xs:dateTime( val )'

Xml Datatype Methods

Initial Title
TSQL Convert Xml DateTime (xs:datetime) to SQL DateTime

Initial Tags

Initial Language