本文介绍了DB2的Date函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在DB2中具有事务详细信息的文件,我的要求是提取最近1个月的交易数据。目前我手动修改日期范围如下。在20170115和20170214之间的TRAN_DATE之前
有没有办法每天手动调整日期?
解决方案
如何使用当前日期
日期算术?
WHERE TRAN_DATE BETWEEN当前日期和(当前日期 - 1个月)
如果您需要 YYYYMMDD
格式,您可以这样转换:
YEAR(CURRENT DATE)* 10000 + MONTH(CURRENT DATE)* 100 + DAY(CURRENT DATE)
I have a file which has transaction details in DB2 and my requirement is extract last 1 months transaction data. Currently I amend the date range manually as bellow.
WHERE TRAN_DATE BETWEEN 20170115 and 20170214
Is there a way to code without manually adjusting the dates daily?
解决方案
How about using current date
and date arithmetics?
WHERE TRAN_DATE BETWEEN current date and (current date - 1 month)
If you need the YYYYMMDD
format, you can convert like this:
YEAR(CURRENT DATE) * 10000 + MONTH(CURRENT DATE) * 100 + DAY(CURRENT DATE)
这篇关于DB2的Date函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!