First & Last Day of Last Month

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
edward_m
Charter Member
Charter Member
Posts: 257
Joined: Fri Jun 24, 2005 9:34 am
Location: Philadelphia,PA

First & Last Day of Last Month

Post 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
jguerrero
Participant
Posts: 21
Joined: Wed Aug 27, 2003 5:12 pm
Location: Chile -South America
Contact:

Post 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?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then take that date and set the day to '01' for the 'first day of previous month date'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

... or just apply a MONTH.FIRST Transform to it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
edward_m
Charter Member
Charter Member
Posts: 257
Joined: Fri Jun 24, 2005 9:34 am
Location: Philadelphia,PA

Post by edward_m »

Thanks to ALL.
All ideas did work for me, as always great people give great ideas
Post Reply