30 pts.
 AS/400 QUERY ; how can I calculate the month and year of 3 months ago in define result fields?
I am using an AS/400 query in which I need the month and year of 3 months ago based on today's date. To get today's date I use current(date) but I need to know the month/year 3 month ago and the month/year of previous month undepending which day of the current month it is. Is that possible?

I already tried with substracting 31 and 93 days but that is not full-proof because of the month february.

 

 

 



Software/Hardware used:
OS/400 V5R3M0
ASKED: October 5, 2009  11:15 AM
UPDATED: October 6, 2009  7:05 AM

Answer Wiki:
You say "query" so I assume you are using SQL ... All flavors of SQL have all kinds of date related functions and functionality. look up the functions and try something like this (this is big DB2 syntax): SELECT MONTH(date_col - 3 MONTHS) , YEAR(date_col - 3 MONTHS) ------------------- or if you mean query/400 WRKDATE CURRENT(DATE) - 3 month MONTH month(CURRENT(DATE) - 3 month) YEAR year(CURRENT(DATE) - 3 month) Here month would be a 2 digit number, like 04 and year would be a 4 digit number, like 2009 http://publib.boulder.ibm.com/iseries/v5r1/ic2924/index.htm?info/q400/rbaf9mst75.htm Phil
Last Wiki Answer Submitted:  October 5, 2009  8:16 pm  by  philpl1jb   44,070 pts.
All Answer Wiki Contributors:  philpl1jb   44,070 pts. , Meandyou   5,205 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Thanks Phil,

this is exactly what I needed in Query/400.

thanks very much,

Chris

 30 pts.