Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Location
    VA
    Posts
    14

    Unanswered: How to return QUARTER from SYSDATE

    I need to return quarter based on the sysdate.
    How can that be done?
    Is there any Oracle build-in date function that returns the quarter?

    Eg. return Jan if today is 3/1/04 or return Apr if today is 5/30/04.

    Thanks in advance!

  2. #2
    Join Date
    Mar 2004
    Posts
    23

    Re: How to return QUARTER from SYSDATE

    1 select (CASE to_char(SYSDATE,'Q')
    2 WHEN '1' THEN 'Jan'
    3 WHEN '2' THEN 'Apr'
    4 WHEN '3' THEN 'Jul'
    5 WHEN '4' THEN 'Oct'
    6 ELSE '???'
    7 END) Qtr
    8* from dual
    SQL> /

    QTR
    ---
    Apr

  3. #3
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: How to return QUARTER from SYSDATE

    Originally posted by clara
    I need to return quarter based on the sysdate.
    How can that be done?
    Is there any Oracle build-in date function that returns the quarter?

    Eg. return Jan if today is 3/1/04 or return Apr if today is 5/30/04.

    Thanks in advance!
    I think this is better solution:

    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
    SELECT to_char(sysdate, 'MON') from dual;
    Last edited by ika; 04-22-04 at 19:57.

  4. #4
    Join Date
    Jan 2004
    Location
    Sochaux (France)
    Posts
    55
    Quote Originally Posted by ika
    I think this is better solution:

    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
    SELECT to_char(sysdate, 'MON') from dual;
    Yes, you will have the month with this request, not the quarter.

    select to_char(round(to_date('13/05/2004', 'DD/MM/YYYY'), 'Q'), 'MON') from dual;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •