Today I needed a PL/SQL funtion to determine next friday's date.
Therefore I had to write a strange PL/SQL function. I'm kind of mixed up - am I complicated?
I'm sure there's a pretty simple Oracle solution out there - hide out!
Hopefully Steven Feuerstein never sees this lines of code. Maybe someon has a better idea than this ....
declare /* Calculate next friday, if today is friday then return today */ function NextFriday return date is vNextFriday date; vNext date; vFR date; vMO date; begin SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY' /*'FREITAG' */)) into vNextFriday FROM dual; select trunc(sysdate)+7 into vNext from dual; if vNextFriday = vNext then select trunc(sysdate) into vFR from dual; else select trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) into vFR from dual; end if; -- Monday vMO := vFR-4; -- Friday return vFR end NextFriday; begin dbms_output.put_line('Next Friday: ' ||NextFriday); end;