AS/400 QUERY ; how can I calculate the month and year of 3 months ago in define result fields?

30 pts.
Tags:
AS/400 Query
OS/400
V5R3
V5R3M0
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Chrisjegoderie
    Thanks Phil, this is exactly what I needed in Query/400. thanks very much, Chris
    30 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following