We help IT Professionals succeed at work.

pull last 10 days data using the  datediff function

Hi,
This code pulls the  last 10 days of data but I want to pull only the last 10 days of data (but not including today’ data).  is there a way to not include today’s data and only start pulling yesterday’s data and beyond that?  thanks

datediff(hh,DATEADD(hour,DATEDIFF(hour,GETUTCDATE(),GETDATE()),[DateTime]),getdate()) <=240

Open in new window

Comment
Watch Question

Try this querry

datediff(hh,DateAdd(day,-11,[DateTime]) ,DateAdd(day,-1,[DateTime])) <= 240
Sorry, it's wrong plz give some time
datediff(hh,[DateTime] ,DateAdd(day,-1,GETDATE())) <= 240

Author

Commented:
still showing today's date: 2011-12-05 13:01:20.000

Author

Commented:
i am sorry it is working now i guess
Most Valuable Expert 2015
Commented:
    > datediff(hh,DATEADD(hour,DATEDIFF(hour,GETUTCDATE(),GETDATE()),
Avoid dateDiff() when possible because it often prevents the db from using indexes.  This comparison is better for a small date:

ie
WHERE   DateColumn >= @tenDaysAgo AND DateColumn < @midnightToday
Top Expert 2012

Commented:
As indicated previously don't use DATEDIFF() for this purpose.

Author

Commented:
tx