DB2 格式化输出 Date

在Oracle中可以使用TO_CHAR()函数来将日期类型的数据转换成字符串输出,并且可以指定输出格式:

 TO_CHAR(date_expression, 'YYYY-MM-DD')
 TO_CHAR(date_expression, 'HH24:MI:SS')

DB2也有TO_CHAR 和 TO_DATE函数,但只能提供固定的转换格式,而且数据类型是timestamp,如下:

TO_CHAR (timestamp_expression,'YYY-MM-DD HH24:MI:SS')
TO_DATE (string_expression, 'YYY-MM-DD HH24:MI:SS')

如果要转换date的格式,直接用CHAR()函数,如下:

CHAR(date_expression,ISO)
CHAR(time_expression,ISO)

ISO指定的日期格式是 yyyy-MM-dd,可以指定其他的格式:

参数日期格式说明
DEF Use a date and time format associated with the territory code.
EUR30.01-2011Use the IBM standard for Europe date and time format.
ISO2011-01-30Use the date and time format of the International Standards Organization.
JIS
2011-01-30
Use the date and time format of the Japanese Industrial Standard.
LOC Use the date and time format in local form associated with the territory code of the database.
USA01/30/2011Use the IBM standard for U.S. date and time format.
 
 
 
参考资料:
 

转载于:https://www.cnblogs.com/zjun/archive/2012/02/15/2353054.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值