How to get the last date of next year in oracle sql?
3 Answers
Last date of next year is one day before the first day of the year after next. So you should be able to get it by adding 24 months to the first day of THIS year, and then subtracting one day. Like this:
select sysdate, add_months(trunc(sysdate, 'y'), 24) - 1 as last_day_next_year from dual;
SYSDATE LAST_DAY_NEXT_YEAR
---------- ------------------
2016-08-04 2017-12-31
1 row selected.
Try this:
select add_months(to_date('31-DEC-' || to_char(current_date, 'YYYY')),12) from dual;
-
1This relies on implicit conversion, so it may not work; for example on my DB it gives: ORA-01843: not a valid month– AleksejCommented Aug 4, 2016 at 15:59
-
If dates are formatted differently by default on your system, simply modify the date string to use the format your system requires. Commented Aug 4, 2016 at 19:21
-
If you need a solution that works independently of the way dates are formatted, then you can specify the format to use in the to_date function:
select add_months(to_date('31-DEC-' || to_char(current_date, 'YYYY'), 'DD-MON-YYYY'),12) from dual;
Commented Aug 4, 2016 at 19:32
Something like...
Select last_day(add_months(sysdate, 12 + (12- to_number(to_char(sysdate, 'mm'))))) from dual;
-
This gives ORA-00923: FROM keyword not found where expected– AleksejCommented Aug 4, 2016 at 16:05