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

/ Published in: SQL
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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

URL: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1920108&SiteID=1

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.