Solved

SQL Query - Get Date Range

Posted on 2007-04-03
4
360 Views
Last Modified: 2008-01-09
I want to return a recordset of results from just today ie:

SELECT * FROM tblLogUser WHERE LogDate =getDate()

getDate() includes the time, which I don't want, so how do I easily filter that out?
0
Comment
Question by:equentin
[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
  • 2
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 18842449
if logdate contains no time portion:
SELECT *
FROM tblLogUser
WHERE LogDate = convert(datetime, convert(varchar(10),getDate(),120), 120)

if log date does contain time portion:

SELECT *
FROM tblLogUser
WHERE LogDate >= convert(datetime, convert(varchar(10),getDate(),120), 120)
AND LogDate < dateadd(day, 1, convert(datetime, convert(varchar(10),getDate(),120), 120))

0
 

Author Comment

by:equentin
ID: 18842526
Okay, that's kind of what I had already (it does have date portion), but I was wondering if there was anything a little more elegant.  Cheers!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18842916
not really.
I have on may servers/database a view/function that returns only the date portion, so it can be used in views/functions easily
0
 

Author Comment

by:equentin
ID: 18842927
Sorry, just noticed I hadn't accepted the solution - my apologies.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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