problem with retrieving necessary date range

  • Thread starter Thread starter Randall Arnold
  • Start date Start date
R

Randall Arnold

I've got a query in an Access data project that pulls in a 52-week range of
values. The date criteria is currently constructed as:

BETWEEN DATEADD(wk, - 53, DATEADD(wk, - 1, GETDATE())) AND DATEADD(wk, - 1,
GETDATE())

This would work fine if I wanted a constant 52 week rolling range from 7
days before the day the query is run. However, I want the query to always
start with the previous Friday, regardless of current weekday, and go back
52 weeks from there.

I've tried various combinations and settings of dateadd, datediff, etc and
so far can't come up with the necessary logic. Any help is appreciated.

Thanks,

Randall Arnold
 
Nevermind! I can't believe I didn't think of this before I posted. The
solution is:

BETWEEN DATEADD(wk, - 52, DATEADD(d, -(6 - datepart(d, GETDATE())),
getdate())) AND DATEADD(d, -(6 - datepart(d, GETDATE())), getdate())

: )

Randall
 
Back
Top