Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

datecheck in sql

Posted on 2001-09-13
6
234 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:florisb
6 Comments
 
LVL 3

Accepted Solution

by:
ahoor earned 50 total points
ID: 6479524
If the table is your_table with a date column date_col:

select * from your_table
where  convert(char(10),date_col,112) = convert(char(10),getdate(),112)
0
 
LVL 2

Author Comment

by:florisb
ID: 6479592
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
0
 
LVL 10

Expert Comment

by:bret
ID: 6479795
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
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:amitpagarwal
ID: 6480280
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.
0
 
LVL 3

Expert Comment

by:ahoor
ID: 6481860
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?
0
 
LVL 2

Author Comment

by:florisb
ID: 6497947
Hi,

Ahoor, your code simply solved the 'problem'.

Thanks to all,
Floris.


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question