Wednesday, April 14, 2010 11:51:20 PM
Create function Working_Days(
Author: Philip Leitch
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.
return abs(datediff(Day, @Date1, @Date2) - 2 * abs(datediff(week, @date1, @date2)))
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