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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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?
Datediff I would not recommend, personally.
Why didn't the query you gave work, except for the obvious missing 'from' clause?
ASKER
Hi,
Ahoor, your code simply solved the 'problem'.
Thanks to all,
Floris.
Ahoor, your code simply solved the 'problem'.
Thanks to all,
Floris.
ASKER
thanks so far.
SELECT *
WHERE club_id = @club_id AND convert(char(10),begindatu
ORDER BY begindatum