Home » SQL & PL/SQL » SQL & PL/SQL » date to DAY
date to DAY [message #185003] Sat, 29 July 2006 16:22 Go to next message
rnallamo
Messages: 24
Registered: August 2005
Junior Member
Hi

create table tt_day(summarydate date);

insert into tt_day values (sysdate)
insert into tt_day values (sysdate+1)
insert into tt_day values (sysdate-1)
insert into tt_day values (sysdate-2)
insert into tt_day values (sysdate-3)
insert into tt_day values (sysdate-4)
insert into tt_day values (sysdate-5)
insert into tt_day values (sysdate-6)
insert into tt_day values (sysdate-7)

select * from tt_day
summarydate
7/28/2006 5:15:42 PM
7/27/2006 5:15:51 PM
7/26/2006 5:15:55 PM
7/25/2006 5:16:04 PM
7/24/2006 5:16:09 PM
7/23/2006 5:16:11 PM
7/29/2006 5:16:24 PM
7/30/2006 5:16:30 PM

i need to find whether the selected date is saturday or sunday
if its saturday or sunday, i have to do some business logic.

appreciate any help
Re: date to DAY [message #185005 is a reply to message #185003] Sat, 29 July 2006 16:32 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This will return Saturdays ("subota" in Croatian) and Sundays ("nedjelja") from the table:
SELECT summarydate, 
       TO_CHAR(summarydate, 'day') dan, 
       LENGTH(TO_CHAR(summarydate, 'day')) len
FROM tt_day
WHERE trim(TO_CHAR(summarydate, 'day')) IN ('subota', 'nedjelja');

[Updated on: Sat, 29 July 2006 16:33]

Report message to a moderator

Re: date to DAY [message #185041 is a reply to message #185003] Sun, 30 July 2006 09:04 Go to previous message
Peter D.
Messages: 19
Registered: June 2006
Location: Warsaw, Poland
Junior Member
i need to find whether the selected date is saturday or sunday
if its saturday or sunday, i have to do some business logic.


I think you need PL/SQL solution.

DECLARE
  v_date DATE;
  v_day VARCHAR2(10);
  CURSOR c1 AS
   SELECT summarydate
   FROM tt_day;
BEGIN
  FOR counter IN c1 LOOP
   FETCH counter.summarydate INTO v_date;
   v_day := TO_CHAR(v_date,'DAY');
   IF v_day = 'SATURDAY' OR v_day = 'SUNDAY') THEN
    // DO WHATEVER YOU WANT
   END IF;
END;


Peter D.
Previous Topic: BULK Collect, CTAS And PL/SQL with COMMIT AFTER 10,000 Records !!
Next Topic: NOT EXISTS
Goto Forum:
  


Current Time: Wed Dec 07 16:17:32 CST 2016

Total time taken to generate the page: 0.06018 seconds