Wednesday, November 18, 2009

ORACLE Same weekday last year

How to get the same weekday last year:
select
case when
to_number(to_char(to_date('28-FEB-2009'),'d') )
-
to_number(to_char(add_months(to_date('28-FEB-2009'),-12),'d') )= 0
then
add_months(to_date('28-FEB-2009'),-12)
else
next_day(add_months(to_date('28-FEB-2009'),-12), to_number(to_char(to_date('28-FEB-2009'),'d') ))
end as DAY_LAST_YEAR_SAME_WEEK_DAY
from
dual;
Till Next Time