Solved

where datetime field is less than 1 day of current datetime

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SQL joins 9 56
Query to return total 6 25
SQL Server 2005 - Comparing Fields' Contents 6 52
Are triggers slow? 7 25
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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