Gray5452
asked on
SQL Syntax convert string to date
This should be easy, but just not working...How does one change an 8 character string 20100204 to a date using either sql syntax or SSIS - tried the DAta conversion but it fails,,,and SQL gives me something funky Dec 9 2 no matter what i use as an arg on the convert function...
ASKER
it looks correct when I do it in a select but when I run the update the dates come out looking like Nov 13 2
try this.
CONVERT(varchar,CONVERT(datetime,date_col,112),101)
check this exampledeclare @col varchar(20) = '20100204'
select @col = CONVERT(varchar,CONVERT(datetime,@col,112),101)
select @col -- 02/04/2010
Try setting it as a variable first and seeing if that works with Sharaths CONVERT.
The other option is to do a CAST
The other option is to do a CAST
CAST('2007-05-08 12:35:29.123' AS datetime) AS 'datetime'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn.microsoft.com/en-us/library/ms187928.aspx