Stored Procedure
I need a sql server stored procedure like i will pass start date and end date for leave and it will return no of days between start date and end date.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Mar 27, 2012, 1:49 AM
Hopefully this will help you to get.
Output:
Gohil JayendrasinhPosted Mar 27, 2012, 1:45 AM
DECLARE @DateOld DATETIME,
@DateNew datetime SET @DateOld = '10-Jan-2012'
SET @DateNew = GETDATE()
SET DATEFIRST 1
SELECT DATEDIFF(DAY, @DateOld, @DateNew) -(2 * DATEDIFF(week, @DateOld, @DateNew))
- CASE
WHEN DATEPART(weekday, @DateOld + @@DATEFIRST) = 1 THEN 1
ELSE 0
END - CASE
WHEN DATEPART(weekday, @DateNew + @@DATEFIRST) = 1 THEN 1
ELSE 0
END