0

I am trying to check in a stored procedure a date in table if it is equal to Today's date.

  Code is 
    DECLARE @p0 datetime
    Set @p0 =GETDATE()
    Select * from testtable 
    where dateCol=@p0

This doesn't work it just gives empty rows. How can I accomplish that? Thanks

Darren
  • 66,506
  • 23
  • 132
  • 141
J. Davidson
  • 3,249
  • 13
  • 52
  • 97
  • 1
    GETDATE() returns the date and time. Possible duplicate of http://stackoverflow.com/questions/467103/ms-sql-date-only-without-time – wgraham Jun 20 '13 at 19:44

2 Answers2

0

You need:

SET @p0 = CONVERT(CHAR(10),GETDATE(),103)  

GETDATE() returns the date and time. You probably have records with todays date but not at this exact time.

Also you don't really need to store it in @p0. You could use the expression directly in the WHERE clause.

Darren
  • 66,506
  • 23
  • 132
  • 141
0

If dateCol is just the date, not DATETIME, you can use:

SELECT *
FROM Table
WHERE dateCol = CAST(GETDATE() AS DATE)
Hart CO
  • 32,944
  • 5
  • 44
  • 59