Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 comparing with a date

Author  Topic 

konark
Yak Posting Veteran

60 Posts

Posted - 2010-08-03 : 13:01:31
what is the most efficient way of comparing a column with a date

For example , I want to compare update_date with getdate()-5
i can do in this way .

convert ( varchar, update_date, 112) = convert ( varchar, getdate()-5, 112)

or i can use greater than and less than the update_date...

But this doesnt look as effient.

Can any one suggest a tested way of comparing date values?

Chandragupta Mourya

Takhyashila

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-08-03 : 13:09:34
Try soemthing like:
WHERE
update_date >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -5)
AND update_date < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -4)
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2010-08-03 : 15:37:02
Well this is also i have tried..
Any other ways guys ?

Chandragupta Mourya

Takhyashila
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-08-03 : 16:50:18
You said, "what is the most efficient way of comparing a column with a date?" Do you want something else? Or do you have some requirement such that you cannot use the method I provided?
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2010-08-03 : 19:39:53
The one you mentioned is also taking a lot of time...

Chandragupta Mourya

Takhyashila
Go to Top of Page
   

- Advertisement -