
July 18th, 2012, 10:59 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 2
Time spent in forums: 15 m 40 sec
Reputation Power: 0
|
|
|
Calculating working days between 2 dates
Hi,
I found the following to return number of mon-fri days between 2 dates but need help to amend it so that it takes in to account public holidays from the Holiday table.
SELECT
top 100
application_id,
application_date as "Start date",
status_date as "End Date",
(DATEDIFF(dd, application_date, status_date) + 1) -(DATEDIFF(wk, application_date, status_date) * 2) -(
CASE WHEN DATENAME(dw, status_date) = 'Sunday' THEN 1 ELSE 0 END) -(CASE WHEN DATENAME(dw, status_date) = 'Saturday' THEN 1 ELSE 0 END) as "Difference"
from applications
Holiday table (holiday_date):
2007-12-26 00:00:00.000
2008-01-01 00:00:00.000
2008-03-21 00:00:00.000
2008-03-24 00:00:00.000
Thanks in advance
Vijay
|