Introduction
This Blog will help you to find out the
working days between two dates.
Description
Here @startdate indicate the first date and @enddate indicate
the last date, by these two date we can calculate the working days for a
company/organization. In this code we use two case, first case is used for
Saturday and other case is used for Sunday Where we use Saturday and
Sunday As non working days. It will help you to exclude these two day's from the working days.
The Code is shown Below
DECLARE @startdate
DATETIME
DECLARE @enddate DATETIME
SET @startdate
= '2013/04/01'
SET @enddate = '2013/04/30'
SELECT
(DATEDIFF(dd, @startdate, @enddate) + 1)
-(DATEDIFF(wk, @startdate,
@enddate) * 2)
-(CASE WHEN DATENAME(dw, @startdate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @enddate) = 'Saturday' THEN 1 ELSE 0 END) as
WorkingDays
Output