Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert char to date

Author  Topic 

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2014-12-26 : 05:31:42
declare @new table(
id int not null identity(1,1),
dat char(10))
insert into @new
select'111214'
union
select'121214'
select cast(dat as datetime)from @new



-----------------------
2011-12-14 00:00:00.000
2012-12-14 00:00:00.000


but me need results it
2014-12-11
2014-12-12

thanks all

http://sql-az.tr.gg/

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-12-26 : 07:44:56
cast((SUBSTRING(dat,5,2)+ SUBSTRING(dat,3,2)+SUBSTRING(dat,1,2)) as date) from new
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2014-12-29 : 02:48:06
thanks
but i was created this script and succefully was running

declare @new table(
id int not null identity(1,1),
dat char(10))
insert into @new
select'111214'
union
select'121214'
select CONVERT(datetime,SUBSTRING(dat,1,2)+'-'+SUBSTRING(dat,3,2)+'-'+SUBSTRING(dat,5,2),5)from @new

http://sql-az.tr.gg/
Go to Top of Page
   

- Advertisement -