SQL Server: Transfer YYYYMMDD-HHMMSS to mm/dd/yyyy hh:mm:ss

后端 未结 3 1466
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 01:15

My SQL Server system is 2016.

As topic, I want to convert YYYYMMDD-HHMMSS to mm/dd/yyyy hh:mm:ss, and use dynamic SQL to fulfill this.

My da

3条回答
  •  旧时难觅i
    2021-01-17 01:44

    This should get the format you want... but there are probably better ways.

    select 
      convert(varchar(16),convert(date,left(ID,8)),101) + 
      ' ' + 
      substring(substring(ID,10,6),1,2) + 
      ':' + 
      substring(substring(ID,10,6),3,2) + 
      ':' + substring(substring(ID,10,6),5,2)
    

提交回复
热议问题