Naveen Kumar

Naveen Kumar

  • NA
  • 73
  • 4.8k

Count Total Days in the two days range in a year

Aug 8 2014 5:13 AM
I need to count the total days between the date ranges specified in a given year.

alter  procedure test @year varchar(10)
as begin

declare @Acount int
Declare @StartDate varchar(20)
Declare @EndDate Varchar(20)
set @StartDate='2014-08-09'
set @EndDate='2014-08-19'
set @Acount=0

if(((YEAR(@StartDate))=@year)and((YEAR(@EndDate))=@year)) 
SET @ACOUNT=@ACOUNT+CONVERT(INT,(SELECT
  (DATEDIFF(dd, @StartDate, @EndDate) + 1)
   -(DATEDIFF(wk, @StartDate, @EndDate) * 2)))
  print @StartDate
  print @Enddate
   print @Acount
End


Here i am getting the @Acount as 7 but the Difference between them is 11. I hope so the saturdays and sundays are excluding from them .

But i need the total All days .How to do .






Answers (1)