Find a quarter from a date

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

Post Reply
sujaoschin
Premium Member
Premium Member
Posts: 102
Joined: Tue Jan 31, 2006 4:13 am

Find a quarter from a date

Post by sujaoschin »

Hi,

I need to find the quarter from the input date '2010-02-01' . The output should be 1 ( which implies the input date falls in 1st quarter)

In server editon, we have Built in-date transform routine like 'QUARTER.TAG . I am unable to find one in PX.

Please let me know.
Sujatha K
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So... a calendar quarter rather than any kind of fiscal quarter, yes? How about a simple Mod(MonthNum,4) + 1 computation?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sujaoschin
Premium Member
Premium Member
Posts: 102
Joined: Tue Jan 31, 2006 4:13 am

Post by sujaoschin »

Yes, Craig. It is for Calendar year.

I am able to find the quarter using the MOD function.

Thanks a lot.
Sujatha K
sujaoschin
Premium Member
Premium Member
Posts: 102
Joined: Tue Jan 31, 2006 4:13 am

Post by sujaoschin »

Hi Craig,

It is coming correctly if the month number is 11 and if the month number is 6 or 12 , the output is coming wrongly
Sujatha K
sujaoschin
Premium Member
Premium Member
Posts: 102
Joined: Tue Jan 31, 2006 4:13 am

Post by sujaoschin »

Let me try this option ( (Monthnum -1)/3) +1 and will post the result
Sujatha K
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry - that was a little simplistic, wasn't it? :oops:

Code: Select all

INT((MONTH(MonthNum)-1)/3)+1
-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 »

You have to do some arithmetic. The first three months you need 1, the second three months you need 2, and so on. Mod(month,3) gives the wrong result, you need something like

Code: Select all

Int(month+(month<>(month-Mod(month,3))/3)
If that seems abstruse, go with a functionally equivalent If..Then..Else construct.

Code: Select all

If Mod(month,3) = 0 Then Int(month/3) Else Int((month + 1)/3)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sujaoschin
Premium Member
Premium Member
Posts: 102
Joined: Tue Jan 31, 2006 4:13 am

Post by sujaoschin »

This issue is resolved and I used the calculation of
((Monthnumber-1)/3)+1 to find the quarter and assigned to an integer variable.


Thanks Craig. Thanks Ray.
Sujatha K
Post Reply