add month to curent date in aqua data studio

616 views Asked by At

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?

2

There are 2 answers

0
Ben On

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

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

0
Paul Vernon On

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 DATEs together? I.e. 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)