Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select records less than todays date 1

Status
Not open for further replies.

douggy

Technical User
Jan 18, 2001
78
GB
Hi there,

I am trying to return all records less than todays date using...

SELECT HitDate FROM dbo.TblStatsPageHits WHERE(HitDate < GETDATE()) ORDER BY HitDate

I still get records from today. I assume its because of the time element. ie it returns anything before the date AND time now. How can I get everything before JUST before todays date. Thus ignoring time element.

I hope you can help

Regards
Mark
 
Code:
SELECT HitDate FROM dbo.TblStatsPageHits WHERE (convert(varchar(8),HitDate,112) < convert(varchar(8),GETDATE(),112)) ORDER BY HitDate

Borislav Borissov
 
I think this would work:

Code:
select hitdate from dbo.tblstatspagehits where convert(varchar,hitdate,112) < convert(varchar,getdate(),112)
 
just remember that if you apply a function to the column, the expression is not sargable and will not perform well

to utilize an index on the column, make sure the column is all by itself on one side of the comparison operator, like my post above

please do see the faq, too :)

r937.com | rudy.ca
 
Why CONVERT() on table (left) side?

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top