Solved

Select dates of current and next week

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

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

Title # Comments Views Activity
php hashing methods 3 50
Can't Find the Homepage on my site 4 47
e commerce steps shown instead of self testing 2 59
How can I use javascript variable in mysql query 21 46
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.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

710 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