Archive

Posts Tagged ‘sql’

Selecting only today’s records

June 19th, 2007 Petros No comments

My database background has been mostly related to Oracle. These days, I am working as a freelancer with a company that heavily uses SQL Server. As a result, I miss knowing stuff out of my mind without having to search.

Today, I wanted to select from a table only those records that where created today. This table has a DateTime column that gets a default value from GetDate(). Here is how I did it:

select
*
from
myTable
where
DateDiff(DAY, MyDateColumn, GetDate()) = 0

Is there a better way?

Categories: tips Tags: ,