sql - Computing datetime from a string? -



sql - Computing datetime from a string? -

i have date , time in csv file : 20140618123022 , column format datetime, question best way convert string '2014-06-18 12:30:22' datetime format ?

i create pool procedure ..

and thinking create utilize or right() , left() , concatenation , right way ?

convert([datetime],(((((((((convert([varchar](4),[data],(0))+'-')+substring([data],(5), (2)))+'-')+substring([data],(7),(2)))+' ')+substring([data],(9), (2)))+':')+substring([data],(11),(2)))+':')+substring([data],(13),(2)),(0))

declare @a varchar(20) set @a='20140618123022' select convert(datetime,(left(@a,4)+'-'+substring(@a,5,2)+'-'+substring(@a,7,2)+' '+substring(@a,9,2)+':'+substring(@a,11,2)+':'+right(@a,2)))

or this!

select convert(datetime,(left(@a,8)+' '+substring(@a,9,2)+':'+substring(@a,11,2)+':'+right(@a,2)))

demo

--returns

2014-06-18 12:30:22.000

sql sql-server-2008

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -