DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2009/1/01'
SET @EndDate = GETDATE()
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)
Assuming the current date is 'May 20, 2009', the number of working days after this query is 100
Thanks, it was exactly what i needed, it helped me alot :)
ReplyDeleteWondefull !
ReplyDeletewrong output
ReplyDelete