richa deb richa deb - 9 months ago 31
SQL Question

How to convert "YYYYMMDDHHMM" format to YYYY/MM/DD HH:MM format in SQL Server?

I have a Column having datetime values as "YYYYMMDDHHMM" format. I want to change it to YYYY/MM/DD HH:MM format. Please help .

Answer Source

If it is a varchar field you can use this:

declare @date varchar(20) = '201703010454';

select left(@date,4) + '/' + substring(@date,5,2) + '/'
       + substring(@date,7,2) + ' ' + substring(@date,9,2)
       + ':' + right(@date,2)