Link to home
Start Free TrialLog in
Avatar of karinos57
karinos57Flag for Afghanistan

asked on

pull last 2 days of data (excluding today's data)

Hi,
How can i pull the last 2 days of data excluding today's data?  I have a column that has a timestamp like this:
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
Avatar of jogos
jogos
Flag of Belgium image

declare @today as date;
set @today = getdate();
select * from dbo.yourtable
where yourdate between @today - 2 and @today
Avatar of karinos57

ASKER

jogos:
this is what i get when i run it:
Operand type clash: date is incompatible with int
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

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
Or staying in same datatype but getting rid off the timestamp from GETDATE()


DECLARE @today as DATETIME
SET @todaty = CAST(FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME)

select * from dbo.yourtable
where yourdate >= @today - 2 
and yourdate < [u][/u]@today

Open in new window

works like a charm