using date in a for... loop [message #179747] |
Wed, 28 June 2006 09:57  |
pully
Messages: 3 Registered: October 2005
|
Junior Member |
|
|
How do i write this loop
i have this three text items as dates:
:date_from
:date_to
:required_days
and my loop is as follows:
:date_to := :date_from + :required_days
for i in :date_from..:date_to loop
if to_char(i,'DAY') = 'SATURDAY' AND to_char(i+1,'DAY') ='SUNDAY' then :date_to := :date_to + 1;
end loop;
|
|
|
|
Re: using date in a for... loop [message #179778 is a reply to message #179752] |
Wed, 28 June 2006 12:37   |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
I wholeheartedly agree with Jim. Jim though may have missed the illogical logic that OP was comparing i and i+1.
OP, you can use your code after you use dates for dates, but you would want to loop from 1 to the difference between the two dates and then add i to the start date (use a date and not a character string!) instead of thinking that you can loop between dates (or in your case character strings).
[Updated on: Wed, 28 June 2006 12:37] Report message to a moderator
|
|
|
Re: using date in a for... loop [message #179802 is a reply to message #179778] |
Wed, 28 June 2006 16:13  |
 |
Littlefoot
Messages: 21826 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
If you, however, want to loop between dates, that can be done too: convert it into the Julian date (which is, actually, a number) and that should do it. For example:BEGIN
FOR i IN TO_NUMBER(TO_CHAR(TO_DATE('20.06.2006.', 'dd.mm.yyyy.'), 'j')) ..
TO_NUMBER(TO_CHAR(TO_DATE('25.06.2006.', 'dd.mm.yyyy.'), 'j'))
LOOP
dbms_output.put_line(TO_DATE(i, 'j'));
END LOOP;
END;
/
|
|
|