简体   繁体   English

在 aqua 数据工作室中将月份添加到当前日期

[英]add month to curent date in aqua data studio

I am trying to develop a report through aqua data studio by using SQL.I am trying to extract report of last month like counting the total number of new users in the last month.我正在尝试使用 SQL 通过 aqua 数据工作室开发报告。我试图提取上个月的报告,例如计算上个月的新用户总数。 Date_Creation is the column when a user is registered in the system. Date_Creation 是用户在系统中注册时的列。 I have tried DATEADD("MONTH",-1,Current_Date) but getting error "Month is invalid in context" .Any Solution/Suggestions?我试过 DATEADD("MONTH",-1,Current_Date) 但收到错误“月份在上下文中无效”。任何解决方案/建议?

DB2 doesn't use DATEADD for date arithmetic, you just, err easier to show. DB2 不使用 DATEADD 进行日期算术,您只是更容易显示。

SELECT * FROM TABLE WHERE DATE_CREATION > CURRENT DATE - 1 MONTH; SELECT * FROM TABLE WHERE DATE_CREATION > 当前日期 - 1 个月;

If you want to add a MONTH , why are you trying to "add" a "date" (which is what I assume DATEADD might mean)?如果你想添加一个MONTH ,你为什么要“添加”一个“日期”(我认为DATEADD可能是这个意思)? What does it mean to add two DATE s together?将两个DATE相加是什么意思? Ie what is the result of '2019-01-01' + '2019-01-01' ?!即 '2019-01-01' + '2019-01-01' 的结果是什么?!

Anyway, I digress.无论如何,我离题了。 You can use ADD_MONTHS if you wish https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0053628.html如果您愿意,您可以使用ADD_MONTHS https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0053628.html

or, use the - 1 MONTH solution, which is just as good (if not better)或者,使用- 1 MONTH解决方案,这同样好(如果不是更好的话)

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

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