Get end of Month based on year and Month

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

puliram
Participant
Posts: 20
Joined: Mon Apr 28, 2008 6:10 pm

Get end of Month based on year and Month

Post by puliram »

Can any one suggest how to get the last day of a month based on my source data

For Example
I am getting from source 200812(year and Month)

Then my output should be 20081231(end of that month and year)

Say one more example
If I am getting 200802(Year and month)

Then my output should be 20080229(end of month which is leap year)

Any Suggestions please
abhijain
Participant
Posts: 88
Joined: Wed Jun 13, 2007 1:10 pm
Location: India

Post by abhijain »

Rgrds,
Abhi
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The logic is to take your year/month, add one month, create a date of the first day of tht month and then subtract a day.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

and to find next month, take first day of current month and add 31 to it.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Or Just use a Time Dimension table.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
puliram
Participant
Posts: 20
Joined: Mon Apr 28, 2008 6:10 pm

Re: Get end of Month based on year and Month

Post by puliram »

Can any one give me the solution for below question using datastage Transformer or any solution using DataStage.

Can any one suggest how to get the last day of a month based on my source data

For Example
I am getting from source 200812(year and Month)

Then my output should be 20081231(end of that month and year)

Say one more example
If I am getting 200802(Year and month)

Then my output should be 20080229(end of month which is leap year)

Any Suggestions please[/quote]
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The solution given in the thread solves your problem as well. Add 1 to the month then subtract a day. That also solves leap year issues.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

do you want someone to write the complete derivation? :? you can search for it, or read datastage manual for datefromdayssince() function. you may need to use it twice.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
rohithmuthyala
Participant
Posts: 57
Joined: Wed Oct 21, 2009 4:46 am
Location: India

Post by rohithmuthyala »

Extract the month part alone.
Check if month is 04,06,09,11 then append 30 to the existing string.
Else if month is 02 and (Year%4)=0 then append 29
Else append 31 to the existing string.

The above can be handled using Stage variables in the Transformer stage.
Rohith
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

... except where the year number is divisible by 400.

Further, the recent earthquake in Chile may have changed the earth's rotation slightly - the year may be marginally shorter. Do you need to worry about that?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ReachKumar
Participant
Posts: 29
Joined: Wed Jan 06, 2010 7:18 am

Post by ReachKumar »

Adding one more point :
Logic to findout Leapyear:

If (Year%400 = 0 ) or ( Year%100 <> 0 and Year%4 = 0 )
Regards,
Kumar
puliram
Participant
Posts: 20
Joined: Mon Apr 28, 2008 6:10 pm

Post by puliram »

ReachKumar wrote:Adding one more point :
Logic to findout Leapyear:

If (Year%400 = 0 ) or ( Year%100 <> 0 and Year%4 = 0 )
% dont work in transformer..wat would be the function instead
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Mod()
-craig

"You can never have too many knives" -- Logan Nine Fingers
puliram
Participant
Posts: 20
Joined: Mon Apr 28, 2008 6:10 pm

Post by puliram »

ReachKumar wrote:Adding one more point :
Logic to findout Leapyear:

If (Year%400 = 0 ) or ( Year%100 <> 0 and Year%4 = 0 )
% dont work in transformer..wat would be the function instead and also we are missing fed 28 month ending
puliram
Participant
Posts: 20
Joined: Mon Apr 28, 2008 6:10 pm

Post by puliram »

rohithmuthyala wrote:Extract the month part alone.
Check if month is 04,06,09,11 then append 30 to the existing string.
Else if month is 02 and (Year%4)=0 then append 29
Else append 31 to the existing string.

we are missing Feb 28 Month ending in this logic and how can we handle % datastage transformer

The above can be handled using Stage variables in the Transformer stage.
Post Reply