在DB2中格式化小时? [英] Format Hour in DB2?

查看:440
本文介绍了在DB2中格式化小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用AM和PM显示db2小时功能?

 从ORDERS选择小时(TIMESTAMP)与ur 

这将发出像5,6,7等。



但是,我想在小时后的AM / PM。



我想Dislpay为5 AM6AM7AM。是否可以在db2?

解决方案

使用 TIME() CHAR()函数:

  SELECT CHAR(TIME(timestamp)美国)
从订单
与UR

虽然老实说,你应该在应用程序层中执行此类型的格式化,而不是SQL层。

(在本地DB2实例上运行的语句)






编辑:



对不起,我以前错过了。通过文档向我展示了一个新功能, VARCHAR_FORMAT()。假设您使用的是DB2 9.5,以下内容应该向您提供您要查找的内容:

  SELECT VARCHAR_FORMAT时间戳,'HH12 AM')
FROM Orders
WITH UR

不幸的是,我无法自己测试,因为iSeries V6R1不支持 HH12 标志( HH24 ,什么? )。否则,你将不得不自己解析出来。


Is there any way to display db2 Hour function with AM and PM?

select hour(TIMESTAMP) from ORDERS with ur 

This will give out like 5,6,7 etc..

But i want AM/PM after the Hour time.

I'd like to Dislpay as 5AM,6AM,7AM. Is it possible in db2?

解决方案

Use the TIME() and CHAR() functions:

SELECT CHAR(TIME(timestamp), USA)
FROM Orders
WITH UR

Although, honestly, you should be doing this type of formatting in the application layer, not the SQL Layer.
(Statement run on my local DB2 instance)


EDIT:

Sorry, I missed that part earlier. Going through the documentation has shown me a new function, VARCHAR_FORMAT(). Assuming you're on DB2 9.5, the following should grant you some form of what you're looking for:

SELECT VARCHAR_FORMAT(timestamp, 'HH12 AM')
FROM Orders
WITH UR

Unfortunately, I can't test this myself, as iSeries V6R1 doesn't support the HH12 flag (HH24 only, what?). Otherwise, you're going to have to parse it out yourself.

这篇关于在DB2中格式化小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆