oracle - PL/SQL --next date based on Frequency -


i looking oracle function or procedure calculate next date based on input date , frequency(yearly,half yearly, quarterly ).

for example

input date     frequency    next occurrence date 1-jan-2016     quarterly     1-apr-2016 1-jan-2016     yearly        1-jan-2017 

look @ oracle function add_months( date, number_months ) monthly, quarterly, yearly results.

for example, next quarter 3 months. if input date first quarter use:

add_months( 01-jan-2016, 3 ) 

to next quarter.

example sql:

select to_date('01-jan-2016', 'dd-mon-yyyy') "input date",        'quarterly' "frequency",        add_months(to_date('01-jan-2016', 'dd-mon-yyyy'), 3) "next occurrence date" dual union select to_date('01-jan-2016', 'dd-mon-yyyy') "input date",        'yearly' "frequency",        add_months(to_date('01-jan-2016', 'dd-mon-yyyy'), 12) "next occurrence date" dual ; 

results:

input date         frequency next occurrence date ------------------ --------- ------------------ 01-jan-16          quarterly 01-apr-16 01-jan-16          yearly    01-jan-17 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -