Solved

All rows today

Posted on 2011-09-09
2
293 Views
Last Modified: 2012-05-12
I have a table. It has a column DateCreated (datetime). I would like to select all rows where DateCreated is today. How is best to do that?
0
Comment
Question by:johnkainn
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
Comment Utility
SELECT *
FROM SomeTable
WHERE DateCreated >= DATEADD(day, DATEDIFF(day, '2000-01-01', GETDATE()), '2000-01-01') AND
    DateCreated < DATEADD(day, DATEDIFF(day, '2000-01-01', GETDATE()) + 1, '2000-01-01')

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
If you can guarantee that DateCreated never has a time portion, you can get away with:

SELECT *
FROM SomeTable
WHERE DateCreated = DATEADD(day, DATEDIFF(day, '2000-01-01', GETDATE()), '2000-01-01')

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now