Page 1 of 1

First & Last Day of Last Month

Posted: Mon Aug 18, 2008 1:54 pm
by edward_m
I want to get first day of previous month date (YYYYMMDD) and last day of previous month date(YYYYMMDD) in datastage job..Please advise me how to get it done in tranformer

Example ..If i run my job today i want 20080701 as first date and 20080731 as last date of previous month

Thanks in advance

Posted: Mon Aug 18, 2008 2:26 pm
by jguerrero
Hi,

In DataStage exists a transform called MONTH.FIRST, it explanation is

"Returns a numeric internal date corresponding to the first day of a month given in MONTH.TAG format (YYYY-MM).
Example: MONTH.FIRST("1993-02") => 9164"

Then you can rest 1 from the result and use oconv to obtain tha last day of the previous month --> LastDay=oconv(result,"D-YMD[4,2,2]")

Now you juas need to repeat MONTH.FIRST with the new result

FirstDay=MONTH.FIRST(LastDay[1,7])

Very clear uh?

Posted: Mon Aug 18, 2008 2:51 pm
by ray.wurlod
The MONTH.FIRST Transform will give you the first day of the month as an internal date.

Subtract one from this to get the last day of the previous month.

Posted: Mon Aug 18, 2008 2:59 pm
by chulett
Then take that date and set the day to '01' for the 'first day of previous month date'.

Posted: Mon Aug 18, 2008 5:10 pm
by ray.wurlod
... or just apply a MONTH.FIRST Transform to it.

Posted: Tue Aug 19, 2008 8:28 am
by edward_m
Thanks to ALL.
All ideas did work for me, as always great people give great ideas