Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Need to exclude weekends from two dates

$
0
0

I'm trying to figure out how to exclude weekends from the DATEDIFF function I have on the SELECT statement below. This code works exactly how I want it to work but I'm having trouble trying to figure out to exclude the weekends. Any help would be greatly appreciated.

Select pst.proposal, pst.sort_code, e.shop, e.pri_code, min(pst.status_date) as begin_date, max(pst.status_date) as end_date,
DATEDIFF(DD, MIN(PST.STATUS_DATE), MAX(PST.STATUS_DATE)) AS DIFTIME

FROM AE_P_PST_E AS PST
INNER JOIN AE_P_PHS_E AS E
ON PST.PROPOSAL = E.PROPOSAL
AND PST.SORT_CODE = E.SORT_CODE

WHERE (PST.ORDER_TYPE NOT IN ('AG','EHS','PM'))
AND (E.STATUS_CODE = 'OPEN' OR E.STATUS_CODE = 'COMPLETE')
AND (E.SHOP = 'CARPENTRY')
AND (E.CATEGORY != 'SHOP TIME')
AND (E.ENT_DATE BETWEEN CONVERT (DATETIME, '2013-08-01 00:00:00', 102) AND CONVERT (DATETIME, '2013-08-30 00:00:00', 102))
GROUP BY PST.PROPOSAL, PST.SORT_CODE, E.PRI_CODE, E.SHOP, E.ENT_DATE
HAVING (NOT (DATEDIFF(MI, MIN(PST.STATUS_DATE), MAX(PST.STATUS_DATE)) = 0 ))
ORDER BY PST.PROPOSAL


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>