richa deb richa deb - 1 year ago 96
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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download