简体   繁体   English

db2日期格式concat特定时间

[英]db2 date format concat specific time

I'm trying to query data that happened between Yesterday 6 AM and Today 6 AM. 我正在尝试查询昨天6 AM和今天6 AM之间发生的数据。

I'm having a problem in concatenation. 我在连接时遇到问题。

This is what I've tried. 这就是我尝试过的。

Where update_time between date(CURRENT DATE,'mm/dd/yyyy 06:00:00')- 1 DAYS 
                      and date(CURRENT DATE,'mm/dd/yyyy 06:00:00')

Try this: 尝试这个:

WHERE UPDATE_TIME 
BETWEEN TIMESTAMP(CHAR(CURRENT DATE,ISO) || ' 06:00:00') - 1 DAY
AND TIMESTAMP(CHAR(CURRENT DATE,ISO) || ' 06:00:00')

Updated to answer X-Zero's comment: 更新以回答X-Zero的评论:

The DB2 function CHAR(CURRENT DATE,ISO) takes the current date, and converts it to a character string in the ISO format. DB2函数CHAR(CURRENT DATE,ISO)获取当前日期,并将其转换为ISO格式的字符串。 Taking today's date, the CHAR function would return "2012-09-18". 以今天的日期为准,CHAR函数将返回“ 2012-09-18”。

Next, we concatenate (||) a time string to the date string. 接下来,我们将时间字符串连接(||)到日期字符串。 The space in the time string creates a character DB2 timestamp in the correct format. 时间字符串中的空格将以正确的格式创建字符DB2时间戳。 "2012-09-18 06:00:00". “ 2012-09-18 06:00:00”。

Finally, the DB2 function TIMESTAMP takes the character DB2 timestamp and converts it to an actual DB2 timestamp. 最后,DB2函数TIMESTAMP使用字符DB2时间戳并将其转换为实际的DB2时间戳。

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

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