Click here to Skip to main content
15,881,876 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am trying using this query t calculate total days in a month but what i want is to select total days in month excluding Sundays. I want total days in month which should not include Sundays.

Query:

select day(EOMonth(GETUTCDATE())) as TotalDays
Posted

 
Share this answer
 
Comments
Hunain Hafeez 15-Feb-14 2:24am    
sir this query returns 28, i am passing parameters i.e. builtin functions in it
Declare @StartDate Date, @EndDate Date, @mydate date
Set @mydate = GETDATE()
Set @StartDate = (SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101))
Set @EndDate = (SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101))


SELECT (DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 1)--EDIT give 2 instead of 1 to exclude saturday also
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900