简体   繁体   English

如何将表中的HOURS和Minutes设置为时间戳

[英]How to Set HOURS and Minutes from a table into a timestamp

Lets say I have a table which storing HOURS and MINUTES in two different column. 可以说我有一个表,它在两个不同的列中存储HOURS和MINUTES。 For example: 例如:

HOURS|MINUTES 
------------------
1|11
2|22
3|33

How can I merge the hours and minutes in my table into current timestamp 如何将表格中的小时和分钟合并到当前时间戳中

My concept are as below 我的概念如下

SELECT TRUNC(CURRENT TIMESTAMP) + HOURS + MINUTES FROM MYTABLE;

try this one 试试这一个

 select current timestamp + HOURS hour + MINUTES  minute 
 from sysibm.sysdummy1  

After several hours of trying i find out that i need to further enhance my table design, instead of storing minute and hours in different column, is better that i store in in single column. 经过数小时的尝试,我发现我需要进一步改进表设计,而不是将分钟和小时存储在不同的列中,而不是将其存储在单个列中更好。 The sample value can be '18:36:00' 样本值可以是“ 18:36:00”

then use the following query to convert it 然后使用以下查询将其转换

(SELECT CAST(? AS TIMESTAMP) + HOUR(TIME(END_TIMESTAMP)) HOURS + MINUTE(TIME(END_TIMESTAMP)) MINUTES FROM MY_TABLE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM