Solved

datecheck in sql

Posted on 2001-09-13
6
231 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now