Working Days
Posted by Philip Leitch
Wednesday, April 14, 2010 10:51:20 PM
Create function Working_Days(
@Date1 Smalldatetime,
@Date2 Smalldatetime)
/*www.prlsoftware.com
Author: Philip Leitch
Date: 2010
Purpose: This function determines the number of working days between two dates.
Copyright: Philip Leitch 2010
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
Notes: The logic is simply the number of days different between the two dates minus 2 times the number of weeks between
the two dates. Holidays and other issues may need to be factored in.
*/
returns int
as
begin
return abs(datediff(Day, @Date1, @Date2) - 2 * abs(datediff(week, @date1, @date2)))
end
go
select dbo.working_days ('12/4/2010', '16/4/2010') --During Week
select dbo.working_days ('16/4/2010', '19/4/2010') --Over weekend
Copyright 2009 Philip Leitch