Date Functions - Finding the quarter of the year [message #166362] |
Wed, 05 April 2006 23:01 |
CW2005
Messages: 29 Registered: February 2005
|
Junior Member |
|
|
Hi All
I'm building a report that requires me to find how many records were created in the 'last quarter'.
In example
Months Jan, Feb, Mar are in Quarter 1.
Months Apr, May, Jun are in Quarter 2.
Months Jul, Aug, Sep are in Quarter 3.
Months Oct, Nov, Dec are in Quarter 4.
If I ran the report today, as we were in April, the current quarter would be considered as Quarter 2. The report would therefore have to report on all records created in Quarter 1.
I dont think there is any date function that will allow me to do this, can anyone help me out?
Thanks in advance.
|
|
|
Re: Date Functions - Finding the quarter of the year [message #166367 is a reply to message #166362] |
Thu, 06 April 2006 00:21 |
RAS_SANKAR
Messages: 42 Registered: March 2006 Location: India
|
Member |
|
|
hi
u try out this code, it may be useful to u.
first u write the following query in query object
select * from table where date between :d1 and :d2
and write the following code in
before-parameter-form trigger
if to_char(sysdate,'mm') in (1,2,3) then
:d1 := to_date('01-jan-'||to_char(sysdate,'yyyy'));
:d2 := to_date('31-mar-'||to_char(sysdate,'yyyy'));
elsif to_char(sysdate,'mm') in (4,5,6) then
:d1 := to_date('01-apr-'||to_char(sysdate,'yyyy'));
:d2 := to_date('30-jun-'||to_char(sysdate,'yyyy'));
elsif to_char(sysdate,'mm') in (7,8,9) then
:d1 := to_date('01-jul-'||to_char(sysdate,'yyyy'));
:d2 := to_date('30-sep-'||to_char(sysdate,'yyyy'));
elsif to_char(sysdate,'mm') in (10,11,12) then
:d1 := to_date('01-oct-'||to_char(sysdate,'yyyy'));
:d2 := to_date('31-dec-'||to_char(sysdate,'yyyy'));
end if;
-Ras
|
|
|
|
Re: Date Functions - Finding the quarter of the year [message #166374 is a reply to message #166369] |
Thu, 06 April 2006 01:10 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
Let's get the good ol' manual out, shall we? In the SQL Reference, Chapter 2: Basic Elements of Oracle SQL, in Table 2-15 (Datetime Format Elements) we find: "Q: Quarter of year (1, 2, 3, 4; JAN-MAR = 1)"
So, we can do it directly:
SQL> SELECT TO_CHAR(d,'Month') themonth
2 , TO_CHAR(d, 'Q') quarter
3 FROM ( SELECT ADD_MONTHS(TRUNC(SYSDATE,'Y'), LEVEL-1) d
4 FROM dual
5 CONNECT BY LEVEL <= 12
6 )
7 /
THEMONTH Q
--------- -
January 1
February 1
March 1
April 2
May 2
June 2
July 3
August 3
September 3
October 4
November 4
December 4
12 rows selected.
MHE
|
|
|
|
|
|
|
Re: Date Functions - Finding the quarter of the year [message #649335 is a reply to message #649307] |
Tue, 22 March 2016 16:56 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Over to the forum ancient thread historian.
So, professor Cadot, thankyou for taking the time to talk to ORAnews. Tell us, is this the oldest thread ever to have been brought back to life? What can science learn from these acts of thread necromancy?
|
|
|
|
|