特殊类型日期转换
原始数据
12 28 2021 5:18PM
12 28 2021 6:08PM
12 29 2021 7:47AM
12 26 2021 9:00PM
02 9 2022 10:44AM
转换为:
2021-12-28 17:18:00.000
2021-12-28 18:08:00.000
2021-12-29 07:47:00.000
2021-12-26 21:00:00.000
2022-02-09 10:44:00.000
SQLserver中规定的日期格式(https://learn.microsoft.com/zh-cn/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver16)
因为无法使用标准的格式进行转换,所以需要先转换为标准格式,然后处理
处理过程如下
with temp(date_convert) as (
select top 10 case SUBSTRING(charge_order_date, 1, 2) when '01' then 'Jan'
when '02' then 'Feb'
when '03' then 'Mar'
when '04' then 'Apr'
when '05' then 'May'
when '06' then 'Jun'
when '07' then 'Jul'
when '08' then 'Aug'
when '09' then 'Sep'
when '10' then 'Oct'
when '11' then 'Nov'
when '12' then 'Dec' end + SUBSTRING(charge_order_date, 3, len(charge_order_date)-2)
from fin_hos_charge_detail)
select convert(datetime, date_convert, 0) from temp;