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
Solved

Select dates of current and next week

Posted on 2006-11-20
2
437 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to count occurrences of each item in an array.

837 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