简体   繁体   中英

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. Date_Creation is the column when a user is registered in the system. I have tried DATEADD("MONTH",-1,Current_Date) but getting error "Month is invalid in context" .Any Solution/Suggestions?

DB2 doesn't use DATEADD for date arithmetic, you just, err easier to show.

SELECT * FROM TABLE WHERE DATE_CREATION > CURRENT DATE - 1 MONTH;

If you want to add a MONTH , why are you trying to "add" a "date" (which is what I assume DATEADD might mean)? What does it mean to add two DATE s together? Ie what is the result of '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

or, use the - 1 MONTH solution, which is just as good (if not better)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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