DateDiff is not working

I am trying to get days difference between two dates. The data type is SmallDatetime.
Select *
from dbo.Tbl1
where (DateDiff(day,Date1,Date2) > = 10)

It is not giving the correct results.How to make it work.

Thanks
KavyaVSAsked:
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.

chaauCommented:
In your example it will only work if Date1 is earlier than Date2 by 10 dates. If you expect to retrieve the records where date1 is later than date2 , you need to use (DateDiff(day,Date2,Date1) > = 10)
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Try d instead of day

This works in both 2012 and 2008R2
Declare @Date1 smalldatetime = '2013-09-10', @Date2 smalldatetime = '2013-09-17'

SELECT DateDiff(d, @Date1, @Date2)

Open in new window

0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Actually, chaau's answer is correct, as day worked in both 2012 and 2008R2 as well.

If it doesn't matter if it's a positive or negative difference, you can use abs()
Declare @Date1 smalldatetime = '2013-09-10', @Date2 smalldatetime = '2013-09-17'

SELECT Abs(DateDiff(day, @Date2, @Date1))

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
HuaMin ChenProblem resolverCommented:
Try
Select *
from dbo.Tbl1
where abs(DateDiff(dd,Date1,Date2) >= 10)

Open in new window

0
KavyaVSAuthor Commented:
Thanks
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 2008

From novice to tech pro — start learning today.