Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Query - Get Date Range

Posted on 2007-04-03
4
Medium Priority
?
365 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

773 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