当前位置: 代码迷 >> Sql Server >> 字符串 转换 日期解决方案
  详细解决方案

字符串 转换 日期解决方案

热度:465   发布时间:2016-04-27 12:38:20.0
字符串 转换 日期

19th May 22:30 


2012-5-19 22:30



------解决方案--------------------
SQL code
declare @date varchar(20)set @date='04th Dec 19:00'select '2012-'+case     when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Jan' then '01-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Feb' then '02-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Mar' then '03-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Apr' then '04-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='May' then '05-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Jun' then '06-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Jul' then '07-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Aug' then '08-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Sep' then '09-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Nov' then '10-'    when rtrim(ltrim(SUBSTRING(@date,CHARINDEX(' ',@date),4)))='Dec' then '11-'    else '12-' end+right('00'+LEFT(@date,CHARINDEX('t',@date)-1),2)+RIGHT(@date,6) as 'date'/*date2012-11-04 19:00*/
  相关解决方案