Today’s Date in T-SQL

by fwhagen Wed, 19 February 2014

I forget this one all the time:  I need today’s date in a SQL query.  In C# it’s DateTime.Today, and in T-SQL it’s:

DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()))

So a simple select that will return all of todays records will look like this:

SELECT * FROM TableName WHERE CompletedDate >= DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()))

Now I won't forget.

Keywords:

Filed Under: DataBase | Programming | SQL

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

TextBox

RecentPosts