Mssql varchar to datetime
- by Dezigo
I have a field varchar(14) = 20090226115644
I need convert it to - 2009-02-26 11:56:44 (datetime format)
My idea. use cast and convert.. but I allways have errors.
Conversion failed when converting datetime from character string.
I made this, but don`t like it..
SELECT
SUBSTRING(move,1,4) + '-' + SUBSTRING(move,5,2) + '-' + SUBSTRING(move,7,2) + ' ' + SUBSTRING(move,9,2) + ':' + SUBSTRING(move,11,2) + ':'+SUBSTRING(move,13,2) as new --
FROM [Test].[dbo].[container_events]
where move IS not null
Result :2009-02-26 11:56:44