Solved

All rows today

Posted on 2011-09-09
2
295 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
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 92

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

777 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