1

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
  • 68,902
  • 24
  • 138
  • 144
J. Davidson
  • 3,297
  • 13
  • 54
  • 102
  • 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

1

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

SELECT *
FROM Table
WHERE dateCol = CAST(GETDATE() AS DATE)
Hart CO
  • 34,064
  • 6
  • 48
  • 63
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
  • 68,902
  • 24
  • 138
  • 144