DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Need some help using date functions to perform quarter calculations. The input is in quarter type format: "Quarter #, YYYY". Based on the input quarter, I need to calculate the previous quarter information.


    Based on the input quarter, calculate the previous quarter:
    Input: "Quarter 1, 2001"
    Output: "Quarter 4, 2000"

    or Input: "Quarter 3, 2001"
    out: "Quarter 2, 2001"

    note: fiscal year starts in November. Therefore, Quarter 1 includes months of Nov, Dec, Jan (in different calendar yrs).

    Thanks for your help!

  2. #2
    Join Date
    Apr 2001
    You could probably just use a decode for this. The following sql*plus script will prompt for a string in the format described and convert it:

    col Quarter new_value quarter
    col Year new_value year
    accept qstring prompt 'String: '

    select substr('&qstring', 9,1) quarter, substr('&qstring', 12,4) year
    from dual

    select decode('&quarter',
    'Quarter 4,'||to_char(to_number('&year')-1),
    'Quarter '||to_char(to_number('&quarter')-1)||',&year')
    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

Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.