Solved

SQL Query - Get Date Range

Posted on 2007-04-03
4
356 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

Suggested Solutions

Title # Comments Views Activity
query question 12 34
Reformat SQL - so SSRS can read the columns 25 30
Limit number of characters returned to 999 9 31
how to make geography query faster?  SQL 7 41
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. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

735 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