Solved

where datetime field is less than 1 day of current datetime

Posted on 2011-03-09
3
723 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

11 Experts available now in Live!

Get 1:1 Help Now