I need a financial year entries based on current or today’s date AND time in Oracle11g DB.
Suppose if we consider today’s date is 1ST April 2013, then i need the outputs as 01-APR-13 and 31-MAR-14.
Our requirement financial Year considered is from April (the current year) to March (following year).
Based on current datetime…the scenario of output depends on the current date-time which falls in the above said period or duration.
Another example: If we take today’s datetime as 28th Dec 2012, then the output is needed as 01-APR-12 and 31-MAR-13.
Please help how to acheive the same in very short format using only SQL.
Consider the below table as
Create table venky (financialYearFrom DATE NOTNULL, financialYearTo DATE NOTNULL);
Something ugly:
If
month > 3then add a year to31-MAR(end_of_period), else substract a year to1-APR(start_of_period).UPDATE: Something nicer:
Substracting 3 months will send you to the correct start year. Truncating to year and adding 3 months sends you to 1 APR. End_of period is 12 months ahead start minus one day.