need help with simple date function in SQL 2007

I have the attached function to calculate business days:
ALTER FUNCTION [dbo].[GetWorkingDays2]
(
@DateEarly DATETIME,
@DateLate DATETIME
)
RETURNS INT

AS
BEGIN
      DECLARE @RAWDAYS INT
IF (DATEDIFF(day, @DateEarly, @DateLate ) = 0)
     BEGIN
       SELECT @RAWDAYS = 1
     END
ELSE
      BEGIN
            SELECT @RAWDAYS = DATEDIFF(day, @DateEarly, @DateLate ) -
            ( 2 * DATEDIFF( week, @DateEarly, @DateLate ) ) -
            CASE WHEN
            DATEPART( weekday, @DateEarly + @@DATEFIRST ) = 1 THEN 1 ELSE 0 END -
            CASE WHEN
            DATEPART( weekday, @DateLate + @@DATEFIRST ) = 1 THEN 1 ELSE 0 END
      END

return  @RAWDAYS  
END
GO

everything except the first if statement is working - basically if the difference between the dates is 0 (same day) then I'd like the business day to still show up/return "1" not a 0. This only works when the dates are exact i.e. 12/12/2007 00:00:00 - 12/12/2007 00:00:00 but not like 12/12/2007 00:00:00 - 12/12/2007 13:20:00... what am I doing wrong? Should I be recasting the date in the diff?
acdagirlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SweatCoderCommented:
Use DATEPART to round off date differences.

http://msdn2.microsoft.com/en-us/library/aa258265(SQL.80).aspx
0
chikenheadCommented:
Try this
ALTER FUNCTION [dbo].[GetWorkingDays2]
(
@DateEarly DATETIME,
@DateLate DATETIME
)
RETURNS INT
 
AS
BEGIN
      DECLARE @RAWDAYS INT
IF (DATEDIFF(day, datepart(day,@DateEarly), datepart(day, @DateLate) ) = 0)
     BEGIN
       SELECT @RAWDAYS = 1
     END
ELSE
      BEGIN
            SELECT @RAWDAYS = DATEDIFF(day, @DateEarly, @DateLate ) -
            ( 2 * DATEDIFF( week, @DateEarly, @DateLate ) ) -
            CASE WHEN
            DATEPART( weekday, @DateEarly + @@DATEFIRST ) = 1 THEN 1 ELSE 0 END -
            CASE WHEN
            DATEPART( weekday, @DateLate + @@DATEFIRST ) = 1 THEN 1 ELSE 0 END
      END
 
return  @RAWDAYS  
END
GO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ee_rleeCommented:
try this

ABS(DATEDIFF(day, @DateEarly, @DateLate)) < 1
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.