|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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?
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Number of days between two dates, w/o Weekends |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|