Quarter/Date Calculations?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Quarter/Date Calculations?

  1. #1
    Join Date
    May 2001
    Posts
    28
    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.

    Example:

    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
    Location
    UK
    Posts
    137
    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',
    '1',
    '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