Need to find next and previous working day in oracle

user573906 picture user573906 · Jan 13, 2011 · Viewed 38.9k times · Source

My query is somewhat like this:

select 1 from dual where :p1_task_date in (sysdate,sysdate+1,sysdate-1) and :p1_task_id is not null

This works fine, but I wanted to get next/previous working days (next/previous week days) instead of sysdate+1 and sysdate-1. I tried something like:

select next_day(sysdate, to_char(sysdate+1,'DAY')) from dual`

but cannot proceed with this :(

Please Help!!!!

Answer

Allan picture Allan · Jan 14, 2011

@Tawman's answer will work, but I prefer this method for readability:

select sysdate as current_date,
       case when to_char(sysdate,'D') in (1,6,7)
            then next_day(sysdate,'Monday')
            else sysdate+1 end as next_weekday,
       case when to_char(sysdate,'D') in (1,2,7)
            then next_day(sysdate-7,'Friday')
            else sysdate-1 end as prev_weekday
from dual

As everyone else has stated, this will only work to exclude weekends, not holidays.