problem with getdate()

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

Hi,

I have the following:

SELECT TransactionID, TransactionDate
FROM dbo.tblTransaction
WHERE (TransactionDate = GETDATE())

This would return empty view result even if there is transaction

Could you please advice

SF
 
The function GetDate() also return the time, so it is very unlikely that its
result will equate a value in the database. You must use the Convert or
Cast function to extract the date part from GetDate() and possibly on
TransactionDate, too.
 
Thank you for your prompt response.

SF
Sylvain Lafontaine said:
The function GetDate() also return the time, so it is very unlikely that
its result will equate a value in the database. You must use the Convert
or Cast function to extract the date part from GetDate() and possibly on
TransactionDate, too.
 
convert(datetime, convert(int, getdate()-.5))

i usually wrap this into a UDF so i dont need to do it a billion
different places

3 cheers for Microsoft for waffling on the Date vs DateTime datatypes
_AGAIN_
 
Back
Top