Page 1 of 1

Determining the last date of previous month

Posted: Wed Aug 03, 2005 1:33 pm
by SonShe
I would like to determine the last date of the previous month in a routine that I later pass as paramter to a job. For example, today I should get 07-31-2005.

I will appreciate your help.

Thanks.

Posted: Wed Aug 03, 2005 2:25 pm
by kduke
You need to get the iconv() of the first of the month then subtract one. Next oconv() it back.

Posted: Wed Aug 03, 2005 3:59 pm
by SonShe
Kim,

Thanks for the reply. I still can't figure out how to get the first date of the month. However I know how I can do that in a transformer using the following code:
DATE.TAG(MONTH.FIRST((MONTH.TAG(@DATE))) - 1)

So I just pasted the same line in the routine which looks as below but gives me compile error. Please help me understand what is going on here.

Thanks.

Code in the routine:

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

CurrDate = DATE.TAG(MONTH.FIRST((MONTH.TAG(@DATE))) - 1)

Ans = CurrDate

Compile error:

Compiling: Source = 'DSU_BP/DSU.pqpCreateCtrlFile', Object = 'DSU_BP.O/DSU.pqpCreateCtrlFile'
**************************************
Array 'DATE.TAG' never dimensioned.
Array 'MONTH.FIRST' never dimensioned.
Array 'MONTH.TAG' never dimensioned.

Posted: Wed Aug 03, 2005 4:28 pm
by kduke
You need to search for DEFFUN to call these functions. First of the month is easy. You need to oconv(@DATE, "D4-") then substring it to get year and month then put it back together.

Code: Select all

Today = oconv(@DATE, "D4-")
ThisYear = field(Today, "-", 3)
ThisMonth = field(Today, "-", 1)
FirstOfMonth = ThisMonth : "-01-" : ThisYear
EndOfLastMonth = oconv(iconv(FirstOfMonth, "D4-") - 1, "D4-")

Posted: Wed Aug 03, 2005 4:34 pm
by ray.wurlod
DATE.TAG, MONTH.FIRST and MONTH.LAST are Transforms and can't be loaded into routines directly. You can, however, load their defining expressions. You may still need to include JOBCONTROL.H. Or, refining Kim's routine into a single expression:

Code: Select all

Oconv(Iconv(Oconv(@DATE, "D-YM[4,2]"):"-01", "DYMD") - 1, "D-YMD[4,2,2]")

Posted: Wed Aug 03, 2005 4:40 pm
by SonShe
Thank you Kim and Ray. Ray when you mentioned "You can, however, load their defining expressions", what does this mean? Can you please expand on this?

Thanks again.

Posted: Wed Aug 03, 2005 8:50 pm
by ray.wurlod
Open the Transform properties from Manager. On the Detail tab is the defining expression for the Transform. It's that which you can copy/paste.

Posted: Thu Aug 04, 2005 7:56 am
by SonShe
Thank you Ray.