我在BD2表中有一个varchar值,如下面的格式
121226145503+0530
我想将此varchar值转换为时间戳格式,如下所示
2012/12/26 14:55:03
答案 0 :(得分:0)
在DB2 9.7中,您还可以使用TO_DATE函数:
date(to_date(column_with_date,'DD-MM-YYYY HH:MI:SS'))
此外,您可以使用TRANSLATE
功能
select
date(translate('DD/MM/YYYY',column-with-the-date,'xyz...'))
from
table
答案 1 :(得分:0)
with d (cwd) as
(values( cast( '121226145503+0530' as varchar(20))))
select cwd as vc_input
, to_date(cwd, 'YYMMDDHH24MISS' ) as ts_from_vc
, varchar_format ( to_date(cwd, 'YYMMDDHH24MISS')
, 'YYYY/MM/DD HH24:MI:SS' ) as vc_from_ts
from d
; -- output from above query follows, as likeness of a report:
....+....1....+....2....+....3....+....4....+....5....+....6....+....
VC_INPUT TS_FROM_VC VC_FROM_TS
121226145503+0530 2012-12-26-14.55.03.000000 2012/12/26 14:55:03
******** End of data ********