Link to home
Start Free TrialLog in
Avatar of florisb
florisb

asked on

datecheck in sql

Hi,

I have a table with a smallDateTime Field. How can I check in a query whether this date is equal to the current date?

Thanks,
Floris

ASKER CERTIFIED SOLUTION
Avatar of ahoor
ahoor
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of florisb
florisb

ASKER

Hmmm, but somehow it doesn't work in the query below; any ideas?

thanks so far.





SELECT *
WHERE club_id = @club_id AND convert(char(10),begindatum,112) <= convert(char(10), getdate(), 112)
ORDER BY begindatum
That would be because *that* query is not checking equality, it is checking "less than or equal", which is a very different thing.  You also don't have a "FROM" clause, which could cause some problems...


Try just:

select *
from <tablename>
where club_id = @club_id
AND begindatum <= getdate()
order by begindatum

-bret
Hope the query below helps.
Thanks,
Amit.

SELECT * from tableName
WHERE club_id = @club_id AND
datediff(day, begindatum, getdate()) = 0
ORDER BY begindatum

In datediff, if smalldatetime values are used, they are converted to datetime values internally for the calculation. Seconds and milliseconds in smalldatetime values are automatically set to 0 for the purpose of the difference calculation.
Hangt er vanaf wat je wilt...

Datediff I would not recommend, personally.

Why didn't the query you gave work, except for the obvious missing 'from' clause?
Avatar of florisb

ASKER

Hi,

Ahoor, your code simply solved the 'problem'.

Thanks to all,
Floris.