0

How to get the last date of next year in oracle sql?

2
  • 3
    Isn't the last date of any year December 31st? What am I missing here?
    – Mureinik
    Commented Aug 4, 2016 at 15:46
  • 1
    Actually, this question is the first google hit, and it has a useful answer. Commented Jan 11, 2021 at 15:14

3 Answers 3

6

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.
-1

Try this:

select add_months(to_date('31-DEC-' || to_char(current_date, 'YYYY')),12) from dual;
3
  • 1
    This relies on implicit conversion, so it may not work; for example on my DB it gives: ORA-01843: not a valid month
    – Aleksej
    Commented 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.
    – Hawthorne
    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;
    – Hawthorne
    Commented Aug 4, 2016 at 19:32
-2

Something like...

Select last_day(add_months(sysdate, 12 + (12- to_number(to_char(sysdate, 'mm'))))) from dual;
1
  • This gives ORA-00923: FROM keyword not found where expected
    – Aleksej
    Commented Aug 4, 2016 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.