compare dates

I have a query like this

Select * from Table
where datecreated = CURRENT_TIMESTAMP

What is the best way to update this query so it only looks at date and not the time?
vbnetcoderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Scott PletcherSenior DBACommented:
where datecreated >= CAST(CURRENT_TIMESTAMP AS date) AND datecreated < DATEADD(DAY, 1, CAST(CURRENT_TIMESTAMP AS date))
1

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
xiao jinshouCommented:
Select * from Table
 where datecreated = DATEPART ( d , getdate() )
0
John TsioumprisSoftware & Systems EngineerCommented:
select * from Table where cast(DateInserted as Date) = cast(Current_TimeStamp as Date)

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Russ SuterCommented:
The "best way" is to store the date information without the time. Any functions you execute in the WHERE clause will slow things down due to function call overhead and/or lack of indexing.

You might want to consider adding a computed column to your table and then indexing on that column. If you're doing these sorts of queries frequently or on large sets of data you'll find performance will be greatly improved using this approach.
0
Scott PletcherSenior DBACommented:
The best way is to avoid using any function on a table column; otherwise you make the condition non-sargable.  Functions on literals/static values don't matter.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
If the datecreated column is a date only data type then you don't need to do nothing as it will truncate the time and will store only the date part.
0
vbnetcoderAuthor Commented:
ty
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
SQL

From novice to tech pro — start learning today.