MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old June 9th, 2004, 02:10 PM
Salizar's Avatar
Salizar Salizar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Posts: 289 Salizar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Number of days between two dates, w/o Weekends

Is there a way to determine the number of days/hours between two dates without adding in weekends?

Reply With Quote
  #2  
Old June 10th, 2004, 12:25 PM
Salizar's Avatar
Salizar Salizar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Posts: 289 Salizar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I have come up with a suitable solution for this problem.
If you are curious here is the function that I created to correctly caculate the datediff with out weekends.

Code:
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE  FUNCTION dbo.WorkDayDiff (@BegDate datetime ,@EndDate DATETIME) 
RETURNS int
BEGIN 

Declare @NumWeek int

set @BegDate = isnull(@BegDate,0) 
set @EndDate = IsNull(@EndDate,0)

set @NumWeek = DateDiff(ww, @BegDate, @EndDate)

Return (datediff(dd, @BegDate, @EndDate) - (@numWeek * 2))
END


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Reply With Quote
  #3  
Old June 11th, 2004, 07:19 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,331 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 7 h 21 m 33 sec
Reputation Power: 891
good start

however, it only works if neither begindate nor enddate is a weekend date!

Code:
declare @BegDate datetime
declare @EndDate datetime
declare @numWeek int
set @BegDate = '2004-06-12'
set @EndDate = '2004-06-13'
set @NumWeek = DateDiff(ww, @BegDate, @EndDate)
select (datediff(dd, @BegDate, @EndDate) - (@numWeek * 2))

result: -1
__________________
r937.com | rudy.ca

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Number of days between two dates, w/o Weekends


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway