Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weekdays Between two Dates 1

Status
Not open for further replies.

BrianTyler

IS-IT--Management
Jan 29, 2003
232
GB
I have also posted this request in the DB2 forum in case there is a database solution to the problem, but there could also be a BO (v5.1.7) solution.

Has anyone come up with a slick method of counting the number of weekdays (Mon - Fri) between two dates.

It is easy to calculate the whole weeks, by subtraction and division, but dealing with the odd days is messy.

It gets even more complicated because, if the first date is a Saturday we treat it as Monday, and if the second date is a Saturday we treat it as Friday.

I don't mind if the solution is in a Designer Object or in a Reporter Variable.
 
Thats where a calendar table can come in handy... Even otherwise you might have write some Functions that takes the inputs and calculates the no of week days... Either way it is possible... Gimme some sample data with all sort of combination and will provide you a solution...

Sri
 
Yes, definately a calenderfile. A nice one would be one that increments a counter with 1 with the exception of saturdays/sundays. A bit of VBA code / or a stored procedure should do the trick....

Consider the DB2 function DAYOFWEEK() that designates the values 1 to sunday and 7 to saturday...

T. Blom
Information analyst
tbl@shimano-eu.com
 
Thanks for your responses.

I have decided to create two objects to hold the dates adjusted for Saturday, then:

days=(int(date2 - date1)/7)*5 = days in whole weeks
+
if dayofweek(date2) >= dayofweek(date1) then dayofweek(date2) - dayofweek(date1)
else
dayofweek(date1) - dayofweek(date2) - 2

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top