Posted By

rengber on 10/03/07


tsql xml DateTime conversion

Versions (?)

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

 / Published in: SQL


This is as small as this can go: 'xs:dateTime(sql:variable("@stringDate"))' It needs to be a literal string for the Value() function.

Xml Datatype

Sql:Variable() Function

'xs:dateTime( val )'

Xml Datatype Methods

  1. declare @stringDate varchar(30);
  2. declare @myXmlDate xml
  3. declare @serializedDate datetime
  4. declare @xQuery varchar(100)
  5. SET @stringDate = '2007-10-03T11:24:07.003+12:00'
  6. SET @myXmlDate = cast('' AS xml) --Gets an empty Xml datatype
  7. SET @serializedDate = @myXmlDate.value('xs:dateTime(sql:variable("@stringDate"))', 'datetime')
  8. SELECT @serializedDate

Report this snippet  

You need to login to post a comment.