Solved

where datetime field is less than 1 day of current datetime

Posted on 2011-03-09
3
726 Views
Last Modified: 2012-06-27
where datetime field is less than 1 day of current datetime
0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
mmr159 earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

23 Experts available now in Live!

Get 1:1 Help Now