Solved

SQL Query - Get Date Range

Posted on 2007-04-03
4
350 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
  • 2
  • 2
4 Comments
 
LVL 142

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 142

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

17 Experts available now in Live!

Get 1:1 Help Now