How to get the next date for a weekday using Oracle

If you ever need to find the next weekday from a given date in Oracle it turns out they have a built in function for doing just that. If you want the next Sunday from yesterday you would do:

SELECT NEXT_DAY(SYSDATE - 1, 'SUN') FROM dual;

Valid entries for the day are: SUN, MON, TUE, WED, THU, FRI, and SAT

Tags: ,

This entry was posted in database administration and tagged ,

2 Comments

  1. ACrush

    Which version is it? In Version 9 this returns exactly the date next SUNDAY will be. Not next weekday. By the way, the valid entries are sometimes not in english. I have an installation where only Russian abbreviations work.

  2. I did my test in 10g. To be clear, this returns the next day of the week with the given name. If you want the day name of tomorrow you should try: SELECT to_char(sysdate + 1, 'DY') FROM dual;

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>