problem with getdate()

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
 
S

Sylvain Lafontaine

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.
 
S

SF

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.
 
A

aaron.kempf

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_
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top