?
Solved

where datetime field is less than 1 day of current datetime

Posted on 2011-03-09
3
Medium Priority
?
738 Views
Last Modified: 2012-06-27
where datetime field is less than 1 day of current datetime
0
Comment
Question by:rgb192
[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
3 Comments
 
LVL 7

Accepted Solution

by:
mmr159 earned 2000 total points
ID: 35085319

SELECT *
FROM t_name
WHERE dt < DATEADD(day,-1,GETDATE())
0
 
LVL 7

Expert Comment

by:mmr159
ID: 35085342
That will retrieve records older than one day, which is what I think you wanted.  Just flip the comparison to get records within one day.

test:

create table t_name (
      dt datetime,
      num int
      )
Go

insert into t_name (dt,num)
select getdate(),0
union
select dateadd(day,-1,getdate()),1
union
select dateadd(day,-2,getdate()),2

SELECT *
FROM t_name
WHERE dt < DATEADD(day,-1,GETDATE())

returns
dt                                    num
2011-03-07 12:31:50.007      2
2011-03-08 12:31:50.007      1
0
 

Author Closing Comment

by:rgb192
ID: 35085902
thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

777 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