Working Days

Posted by Philip Leitch Wednesday, April 14, 2010 11:51:20 PM Categories: Date and Time Scalar Function

Create function Working_Days(
 @Date1  Smalldatetime,
 @Date2  Smalldatetime)
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
    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


You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?