Click here to Skip to main content
15,887,267 members
Articles / Programming Languages / SQL

Fetching Data from a Specific Week Relative to a Date in SQL

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
14 Sep 2021CPOL2 min read 8.3K   2  
How do you get last weeks data only? It's a little more complex than you might have thought
A QA question wanted "the last week of data" and it got me thinking. It's easy to use the DATEADD function with the "WW" interval, but that subtracts seven days from today. That's not the same as "last week" because "last week" started on a Sunday, and ended just before midnight on the following Sunday. Or Saturday, if you are in Israel. Or Monday if that is your company rule. So how do you work that out?

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Comments and Discussions