This is what I have:
CREATE OR REPLACE FUNCTION WEEKEND_DATE
(DATEIN IN DATE)
RETURN DATE AS
DATE_RESULT DATE;
BEGIN
DATE_RESULT := trunc(DATEIN) - 7;
RETURN DATE_RESULT;
END WEEKEND_DATE;
Main Topics
Browse All TopicsI would like to create a function to get the first day of the week(Sunday) by using the sysdate and if the value return is Sunday, I would like to get the previous Sunday's date.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You have to consider the default language used in your Oracle data base. I think the following will be work best:
CREATE OR REPLACE FUNCTION WEEKEND_DATE (DATEIN IN DATE)
RETURN DATE AS
DATE_RESULT DATE;
BEGIN
select DATEIN - num_of_days + 1
into date_result;
from (
select decode(to_number(to_char(D
from dual);
RETURN DATE_RESULT;
END WEEKEND_DATE;
you can do this in many ways.. i have used your function to make it return date of last sunday if the date you are passing is a sunday.
If you are passing a date which is not a sunday, then that date itself returned as it is.
We can even do this in one sql itself,
select case when to_char(datein,'D') = 1 then datein - 7 else datein end my_date_val
from dual;
-- you can change the dual to your tablename and also you can change datein field name to a column which is there in your table.
Thanks
This function will return the date of the Sunday prior to the date passed in and, if that date is a Sunday will return the date of the previous Sunday.
create or replace function return_1st_day(date_in in date)
return date is
v_day pls_integer;
v_1st date;
begin
v_day := to_number(to_char(date_in,
if v_day = 1 then
v_1st := date_in - 7;
else v_1st := date_in - v_day + 1;
end if;
return v_1st;
end;
/
Business Accounts
Answer for Membership
by: awking00Posted on 2007-11-06 at 11:14:18ID: 20226626
create or replace function return_date
return date is
v_date date := sysdate;
begin
if to_char(v_date,'D') = '1'
then v_date := sysdate - 7;
end if;
return v_date;
end;
/