C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Count sunaday in a month


Posted Date: 24 Dec 2008      Posted By: Saurabh Chandak      Member Level: Silver     Points: 1   Responses: 3




Hi Friend


I have a Sp and it have two parameter's (@month,@year,@day). I want to insert month ,year and day such as mon ,tue ,sun ,sat,than print the Number of day in particular month.
------------

execute:
--------

exec datee 12 2008 sun

output is:
__________

sunady : 5





Responses

Author: Tejinder Singh Barnala    24 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 4

try it........

create proc getweeekdayinmonth(@year int, @month int, @day varchar(3))
as

declare @date as datetime
declare @loopcounter as int
set @loopcounter = 0
set @date = (select cast(@year as varchar) + '/' + cast(@month as varchar) + '/' + '01')
while @month = month(@date)
begin
if(substring(datename(dw,@date),1, 3) = @day)
begin
set @loopcounter = @loopcounter + 1
end
set @date = dateadd(dd,1,@date)
end
select @year as [year], @month as [month], @day as [day], @loopcounter as counter


go



exec getweeekdayinmonth 2008,12,'sun' /*enter first three digit of weekday name*/

Many Thanks
Tejinder Singh Barnala
/*I have the simplest tastes. I am always satisfied with the best*/



Author: Santhosh Aravind    24 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 3

declare @month int,@year int, @day varchar(10), @NoOfDays int
declare @d1 datetime


set @day = 'sun'
set @year = 2008
set @month = 12

SET @NoOfDays = 0

set @d1 = cast(cast(@year as varchar) + '/' + cast(@month as varchar) + '/01' as datetime)

while @month = month(@d1)
begin
if(SUBSTRING(DATENAME(dw,@d1),1, 3) = @day)
set @NoOfDays = @NoOfDays + 1

set @d1 = DATEADD(dd,1,@d1)
end

SELECT @NoOfDays



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Packages Using BI
Previous : how to create controls through sql
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use