Wrox Programmer Forums
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 24th, 2008, 12:13 PM
Authorized User
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jonsey Send a message via Yahoo to jonsey
Default calculating work_days

I have a table what has a set of start_dt and end_dt. What I'm looking for is within SQL figuring out the number of working days between two dates. The working days would only be Monday - Friday not including holidays. Any help would be great.

Thanks in Advance

Old February 5th, 2008, 05:37 PM
Friend of Wrox
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts

So you want a 1 for every Mon thru friday and a zero for every sat and sunday.

There are two different methods for doing this. One is to create a date table and put in one row for every day and have a collumn with a value of 1 if its a work day or not. Then you relate on day to that table and sum this column.

Another shortcut is to do a case statement and sum it. I don't have a SQL server available to me to test it right now but here is the basic idea.

sum (case somedate when monday = 1
                   when tuesday = 1
                   when wed = 1
                   when thur = 1
                   when fri = 1
                   else 0

You can determine the mon-friday using date part. It's not the exact code but this should give you the idea.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating time Marta Access 0 April 15th, 2008 10:34 PM
Calculating ashik112 ASP.NET 1.0 and 1.1 Basics 2 February 14th, 2007 12:49 PM
calculating grand total blkskullwork Javascript 2 December 18th, 2006 10:36 AM
calculating values aceconcepts PHP How-To 0 February 16th, 2006 09:01 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.