Link to home
Start Free TrialLog in
Avatar of Gray5452
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...
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

CONVERT(datetime, yourfield, 112)

http://msdn.microsoft.com/en-us/library/ms187928.aspx
Avatar of Gray5452
Gray5452

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)

Open in new window

check this example
declare @col varchar(20) = '20100204'
select @col = CONVERT(varchar,CONVERT(datetime,@col,112),101)
select @col -- 02/04/2010

Open in new window

Try setting it as a variable first and seeing if that works with Sharaths CONVERT.

The other option is to do a CAST

CAST('2007-05-08 12:35:29.123' AS datetime) AS 'datetime' 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kumarnimavat
kumarnimavat
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial