' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ' Copyright (c) 2001 James P. MacLennan All Rights Reserved ' Questions? Comments? Suggestions? Let me know ... www.cazh1.com ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details. ' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- CREATE FUNCTION fnGetWorkingDays ( @StartDate datetime, @EndDate datetime ) RETURNS INT AS BEGIN DECLARE @workdays int DECLARE @dayofweek int DECLARE @count int DECLARE @days int set @workdays = 0 set @count = 0 set @days = DATEDIFF(day, @StartDate, @EndDate) while @count <= @days begin set @dayofweek = DATEPART(dw, DATEADD(day, @count, @StartDate)) if (@dayofweek>1 and @dayofweek<7) set @workdays = @workdays + 1 set @count = @count + 1 End RETURN ( @workdays ) END