Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add_week function? 1

Status
Not open for further replies.

Glowworm27

Programmer
May 30, 2003
587
US
Oracle had an Add_Month function, is there an Add_Week function?

Does anyone have an Add_Week function?

I need to be able to add and subtract weeks from a date variable.

Thanks in advance.
G

George Oakes
Check out this awsome .Net Resource!
 
George,

Here ya' go:
Code:
create or replace function add_weeks (date_in date, how_many number)
    return date
is
begin
    return date_in+(how_many*7);
end;
/
Function created.
Here are sample invocations and results:
Code:
col a heading "ADD_WEEKS|Result" format a20
select to_char(add_weeks(sysdate,2),'dd-MON-yyyy hh24:mi:ss') a from dual;

ADD_WEEKS
Result
--------------------
15-NOV-2005 08:57:25

select to_char(add_weeks(sysdate,-2),'dd-MON-yyyy hh24:mi:ss') a from dual;

ADD_WEEKS
Result
--------------------
18-OCT-2005 08:59:33
Let us know if this is what you wanted.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top