Try this for string to DateTime
BEGIN
Declare @DateTimeValue varchar(20)
SET @DateTimeValue = 'Sam20101201121212'
Declare @Name varchar(3), @DateValue char(8) , @TimeValue char(6)
SELECT @Name = substring(@DateTimeValue,1,3)
SELECT @DateValue = substring(@DateTimeValue,4,8)
SELECT @DateValue
SELECT @TimeValue = substring(@DateTimeValue,12, len(@DateTimeValue) - 1)
SELECT @TimeValue
SELECT @DateTimeValue = convert(varchar, convert(datetime, @DateValue), 111)
+ ' ' + substring(@TimeValue, 1, 2)
+ ':' + substring(@TimeValue, 3, 2)
+ ':' + substring(@TimeValue, 5, len(@TimeValue) - 1)
SELECT @DateTimeValue
END
Wednesday, November 24, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment