AS/400 QUERY ; how can I calculate the month and year of 3 months ago in define result fields?
15 pts.
0
Q:
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: Oct 5 2009  11:15 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
24600 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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 Answered: Oct 5 2009  8:16 PM GMT by Philpl1jb   24600 pts.
Latest Contributors: Meandyou   1840 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Chrisjegoderie   15 pts.  |   Oct 6 2009  7:05AM GMT

Thanks Phil,

this is exactly what I needed in Query/400.

thanks very much,

Chris

 
0