Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select dates of current and next week

Posted on 2006-11-20
2
Medium Priority
?
442 Views
Last Modified: 2013-12-12
I have a database which has product codes and release dates.

I want to be able to select all items that have a release date that falls within the current week.

I want a seperate select which selects all items that have a release date that falls within the following week.

Is there a way to set up the mysql select for the dates to fall in a certain week?  Or will I have to use a date range instead?

Example of use:  SELECT * FROM products_table where  GET_WEEK(product_release_date) = CURRENT_WEEK.
0
Comment
Question by:baumli1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:baumli1
ID: 17980311
Here is solution that I figured out:

Current Week:
SELECT WEEK(CURRENT_DATE(),2);

Next Week:
SELECT (WEEK(CURRENT_DATE(),2) + '1');


Current Week:
SELECT * FROM `products` WHERE WEEK(release_date,2) = WEEK(CURRENT_DATE(),2);


Next Week:
SELECT * FROM `products` WHERE WEEK(release_date,2) = (WEEK(CURRENT_DATE(),2) + '1');


The "2" in SELECT WEEK(CURRENT_DATE(),2); determines if the week starts with Sunday or Monday and if the year has 0-53 or 1-53 weeks.  In my cases, I chose 1-53 weeks, and week starts with a Sunday.

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 0 total points
ID: 18097606
PAQed with points refunded
angelIII, page editor
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question