Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

datecheck in sql

Posted on 2001-09-13
6
Medium Priority
?
241 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
[X]
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
6 Comments
 
LVL 3

Accepted Solution

by:
ahoor earned 200 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
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

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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