Solved

Select dates of current and next week

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

Accepted Solution

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now