Round date to fiscal year

Posted by Dave Jarvis on Stack Overflow See other posts from Stack Overflow or by Dave Jarvis
Published on 2010-04-20T21:41:18Z Indexed on 2010/04/20 21:43 UTC
Read the original article Hit count: 332

Filed under:
|
|

The following database view rounds the date back to the closest fiscal year (April 1st):

CREATE OR REPLACE VIEW FISCAL_YEAR_VW AS
SELECT
  CASE
    WHEN to_number(to_char( SYSDATE, 'MM' )) < 4 THEN    
      to_date('1-APR-'||to_char(add_months(SYSDATE, -12), 'YYYY'), 'dd-MON-yyyy')
    ELSE
      to_date('1-APR-'||to_char(SYSDATE, 'YYYY'), 'dd-MON-yyyy')
  END AS fiscal_year
FROM
  dual;

This allows us to calculate the current fiscal year based on today's date.

How can this calculation be simplified or optimized?

© Stack Overflow or respective owner

Related posts about oracle11g

Related posts about sql