How can I subtract one month of a date in a SERVER JOB?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 161
- Joined: Mon Mar 17, 2008 10:33 am
How can I subtract one month of a date in a SERVER JOB?
How can I subtract one month of a date in a SERVER JOB?
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
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 and subtract 30.
If it is only 30 days, you can do
Code: Select all
IConv(Date,'J')
-
- Participant
- Posts: 161
- Joined: Mon Mar 17, 2008 10:33 am
-
- Participant
- Posts: 161
- Joined: Mon Mar 17, 2008 10:33 am
-
- Participant
- Posts: 161
- Joined: Mon Mar 17, 2008 10:33 am
$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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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 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
"If I had asked people what they wanted they would have said faster horses"
Henry Ford
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: