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:

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

Is there a better way?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s