Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

where datetime field is less than 1 day of current datetime

where datetime field is less than 1 day of current datetime
ASKER CERTIFIED SOLUTION
Avatar of mmr159
mmr159

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmr159
mmr159

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
Avatar of rgb192

ASKER

thanks