Solved

All rows today

Posted on 2011-09-09
2
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 36513737
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 93

Expert Comment

by:Patrick Matthews
ID: 36513741
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

630 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