Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

All rows today

Posted on 2011-09-09
2
Medium Priority
?
302 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 93

Accepted Solution

by:
Patrick Matthews earned 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

916 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