Important alert: (current site time 7/15/2013 7:13:38 PM EDT)
 

VB icon

allday.sql

Email
Submitted on: 5/8/2002 8:25:56 AM
By: Dhairyasheel Tawde  
Level: Beginner
User Rating: By 2 Users
Compatibility: SQL Server 7.0, SQL Server 6.5 and earlier, Informix , Oracle, Other
Views: 14873
(About the author)
 
     You enter a day say 'monday' & it finds the dates of all mondays in the month.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: allday.sql
-- Description:You enter a day say 'monday' & it finds the dates of all mondays in the month.
-- By: Dhairyasheel Tawde
--
-- Inputs:One just has to input the day in quotes like say
'monday' or 'tuesday' etc.
--
-- Returns:it returns the dates, corresponding to the day entered, in the current month.
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=465&lngWId=5--for details.--**************************************

declare
x date;
y date;
z date;
a char(10):= &day;
b char(10);
begin
select trunc(to_date(sysdate),'month') into x from dual;
select to_char(x,'day') into b from dual;
select last_day(sysdate) into y from dual;
dbms_output.put_line(a);
if a=b then
dbms_output.put_line(x);
end if;
loop
	select next_day(x,a) into z from dual;
 
	x:=z;
	exit when x>y;
	dbms_output.put_line(z);
end loop;
end;


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

12/3/2002 9:17:13 PM

This is not working...not even ran.
(If this comment was disrespectful, please report it.)

 
8/1/2006 8:11:55 AMUmar siddique

how to run this code... either this is a store procedure or UDF.. plz reply
(If this comment was disrespectful, please report it.)

 
7/16/2008 7:39:12 PMAndy Archer

Works fine in Oracle, as an anonymous block that could be incorporated into a stored procedure or function. Below is a SQL*Plus execution, with lines 5, 10, 11, and 12 modified to not require the single quotes on day input, and to get away from the Select from DUAL (which is not required and adds some overhead).

SQL> declare
2 x date;
3 y date;
4 z date;
5 a char(10):= '&day';
6 b char(10);
7
8
9 begin
10 x := trunc(to_date(sysdate),'month');
11 b := to_char(x,'day');
12 y := last_day(sysdate);
13 dbms_output.put_line(a);
14 IF a=b THEN
15 dbms_output.put_line(x);
16 END if;
17 loop
18 SELECT next_day(x,a) INTO z FROM dual;
19
20 x:=z;
21 EXIT WHEN x>y;
22 dbms_output.put_line(z);
23 END loop;
24 end;
25 /
Enter value for day: monday
old 5: a char(10):= '&day';
new 5: a char(10):= 'monday';
monday
07-JUL-08
14-JUL-08
21-JUL-08
28-JUL-08

(If this comment was disrespectful, please report it.)

 
6/27/2009 2:03:41 PMvpaitl

very good
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.