Page 1 of 1

Find a quarter from a date

Posted: Tue Feb 16, 2010 10:10 pm
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.

Posted: Tue Feb 16, 2010 10:30 pm
by chulett
So... a calendar quarter rather than any kind of fiscal quarter, yes? How about a simple Mod(MonthNum,4) + 1 computation?

Posted: Tue Feb 16, 2010 11:04 pm
by sujaoschin
Yes, Craig. It is for Calendar year.

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

Thanks a lot.

Posted: Tue Feb 16, 2010 11:23 pm
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

Posted: Tue Feb 16, 2010 11:29 pm
by sujaoschin
Let me try this option ( (Monthnum -1)/3) +1 and will post the result

Posted: Tue Feb 16, 2010 11:33 pm
by chulett
Sorry - that was a little simplistic, wasn't it? :oops:

Code: Select all

INT((MONTH(MonthNum)-1)/3)+1

Posted: Tue Feb 16, 2010 11:41 pm
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)

Posted: Wed Feb 17, 2010 3:58 pm
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.