SERPland Oracle, PL/SQL, PHP, Autos, Bungalow-Hotels and more …

7Nov/073

Calculate next (this) friday date with pl/sql – hide out!


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 function NextFriday return date is vNextFriday date; vNext date; vFR date; vMO date; begin SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY' )) 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;

Comments (3) Trackbacks (0)
  1. I’m looking for code to determine the “2nd Friday of the month” and I found this:

    select next_day(sysdate,’FRIDAY’) as NEXT_DAY from dual

    however, this prints the next Friday, not the 2nd Friday.

    Thought I’d share.

  2. SELECT DATE(DATE_ADD(‘2010-05-21′, INTERVAL 6 – DAYOFWEEK(‘2010-05-21′) DAY))

  3. there is a small mistake, because saturdays are considered same week. solution is to add 1 day to the date you wanna check:

    SELECT
    DATE(
    DATE_ADD(
    ‘2010-05-19′ + INTERVAL 1 DAY,
    INTERVAL 6 – DAYOFWEEK(‘2010-05-19′ + INTERVAL 1 DAY) DAY
    )
    )


Leave a comment


No trackbacks yet.

You might also like

using the anydata datatype in oracle -------------------------------------------------------------------------------- -- sys.anydata.sql -------------------------------------------------------------------------------- --...
I’m A Celebrity, GET ME out OF here! Julia showing skin and Isabel as she was created by God – You dont’t have to hide a pretty body I’m A Celebrity, GET ME out OF here! You dont't have to hide a pretty body.... Isabel as she was...
Naming and Coding Standards for SQL and PL/SQL – Some things I cant agree As written by William Robertson (based on Steven Feuerstein), by using coding standards supports...
Offering for Oracle 7.2.3 DDL scripts – show objects with Enlighten Thank you for your CAST application mining  inquiry. Enclosed we send a commercial offer to you as...
Grab This Widget