Selecting only today's records

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:

[sourcecode language=”SQL”]
select *
from myTable
where DateDiff(DAY, MyDateColumn, GetDate()) = 0

Is there a better way?

Leave a Reply