October 26, 2017 at 2:37 pm
DATETIME = DATEADD(DAY,-6,@Yesterday)
DATETIME = CAST(GETDATE() AS DATE)
So that gets me data from a week ago, to today. But I am having trouble writing so I only get the 7th day (back) of data.
DATETIME =DATEADD(DAY,DATEDIFF(DAY,-6,GETDATE()),0)
??
October 26, 2017 at 2:41 pm
chef423 - Thursday, October 26, 2017 2:37 PMDATETIME = DATEADD(DAY,-6,@Yesterday)
DATETIME = CAST(GETDATE() AS DATE)
So that gets me data from a week ago, to today. But I am having trouble writing so I only get the 7th day (back) of data.
DATETIME =DATEADD(DAY,DATEDIFF(DAY,-6,GETDATE()),0)
??
This doesnt error but I return no dataDATETIME = DATEADD(DAY,DATEDIFF(DAY,-6,GETDATE()),-6)
October 26, 2017 at 3:04 pm
This has to be one of the vaguest and most unclear questions I've ever seen on this site. But is this what you're getting at?
SELECT [mycrap]
FROM [mytable]
WHERE
[mydate] >= DATEADD(DAY,-7,CAST(GETDATE() AS DATE)) AND
[mydate] < DATEADD(DAY,-6,CAST(GETDATE() AS DATE))
October 26, 2017 at 3:07 pm
autoexcrement - Thursday, October 26, 2017 3:04 PMThis has to be one of the vaguest and most unclear questions I've ever seen on this site. But is this what you're getting at?
SELECT [mycrap]
FROM [mytable]
WHERE
[mydate] >= DATEADD(DAY,-7,CAST(GETDATE() AS DATE)) AND
[mydate] < DATEADD(DAY,-6,CAST(GETDATE() AS DATE))
That was right in front me!
Thanks!
October 26, 2017 at 3:12 pm
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
October 26, 2017 at 5:41 pm
Or:
SELECT [mycrap]
FROM [mytable]
WHERE
CAST([mydate] AS DATE) = DATEADD(DAY,-7,CAST(GETDATE() AS DATE))
October 26, 2017 at 5:52 pm
^ but isn't that "non-sargable"?
October 26, 2017 at 5:59 pm
autoexcrement - Thursday, October 26, 2017 5:52 PM^ but isn't that "non-sargable"?
Actually, it is sargable. One of the quirks of the date/time data types.
October 26, 2017 at 6:05 pm
I always learn something here! Never fails.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply