sql compare date ranges based on week#'s

I am looking for a way to design a query in SQL to  compare date ranges based on week#
current years  week# range compared to previous year(s) date ranges with the same week# as current period.

one issue i have seen is some years have 53 weeks?

any help or guidance would be greatly appreciated
schuitkdsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

schuitkdsAuthor Commented:
also want to use Mondays as the first day of the week
Kyle AbrahamsSenior .Net DeveloperCommented:
I have found the f_table_date function found here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519

to be extremely powerful and helpful.


select * from dbo.F_TABLE_DATE('1/1/2015', '1/1/2016')

you have the start_of_week_starting_mon_date as a field and the iso_week_no as a week number.
Tomas Helgi JohannssonCommented:
Hi!

You can use the Date functions for this. :)
https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html

The first thing you will need to ask yourself is how is the data stored in the table ? Is it Date or Time or integer (for example weeknumber or year).
From that point you can easilly construct a sql query.
For example
select * from mytable
where week(mydatecolumn,1) between 40 and 52;

This query expects that mydatecolumn is a Date column and returns all data that is between week 40 and 52 and where the week starts on Mondays.

Regards,
     Tomas Helgi

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.