problem with retrieving necessary date range

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
 
R

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top