How can I subtract one month of a date in a SERVER JOB?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
igorbmartins
Participant
Posts: 161
Joined: Mon Mar 17, 2008 10:33 am

How can I subtract one month of a date in a SERVER JOB?

Post by igorbmartins »

How can I subtract one month of a date in a SERVER JOB?
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Does 1 month imply 30 days or same date previous month ? What if it is 30th March ?

If it is only 30 days, you can do

Code: Select all

IConv(Date,'J')
and subtract 30.
igorbmartins
Participant
Posts: 161
Joined: Mon Mar 17, 2008 10:33 am

Post by igorbmartins »

I want to do something similar to ORACLE add_months:
select Add_months(sysdate, -1) from dual
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Which doesn't really answer the question, especially for people without Oracle experience. Specifically, how do you define a month? As asked, what does that Oracle function give you when you subtract 1 month from March 30th?
-craig

"You can never have too many knives" -- Logan Nine Fingers
igorbmartins
Participant
Posts: 161
Joined: Mon Mar 17, 2008 10:33 am

Post by igorbmartins »

select Add_months(sysdate, -1) as DATE1, sysdate as DATE2 from dual

DATE1= 2010-08-17
DATE2=2010-09-17
igorbmartins
Participant
Posts: 161
Joined: Mon Mar 17, 2008 10:33 am

Post by igorbmartins »

$INCLUDE DSINCLUDE DSJ_XFUNCS.H

DATA_FIM = oconv(Date(),'D.YMD[4,2,2]')
ANO=SUBSTRINGS(DATA_FIM ,1,4)
MES=SUBSTRINGS(DATA_FIM ,6,2)

* ARRUMA ANO
IF MES = '01' THEN
ANO = ANO -1
END


* ARRUMA MES
IF MES = '01' THEN
MES = '12'
END
ELSE
MES = MES-1
END

IF MES < 10 THEN
MES=0:MES
END




*COMPOE DATA
DIA=21
DATA_INICIO=ANO:'.':MES:'.':DIA

Call DSLogInfo("DATA_INICIO= ": DATA_INICIO,"JOB CONTROL")
Call DSLogInfo("DATA_FIM = ": DATA_FIM ,"JOB CONTROL")

Call DSSetUserStatus(DATA_INICIO:';':DATA_FIM )
Ans=DATA_INICIO:';':DATA_FIM
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You need also to handle dates such as March 30.

Check out the date routines in this file
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jeawin
Participant
Posts: 18
Joined: Mon Oct 04, 2004 6:49 am
Location: Milton Keynes
Contact:

Post by jeawin »

I have a routine to add days, months or years to a date, which correctly handles month end dates (for instance 28/02 + 1 month = 31/03). It will obviously need tweaking to subtract dates, but the principle is there.

If you are interested send me a personal email address and I'll send you the DataBasic code.
_______________________________________
"If I had asked people what they wanted they would have said faster horses"
Henry Ford
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Mine do allow you to add negative offsets. ;)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply