Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a query

Status
Not open for further replies.

WizyWyg

Technical User
Jan 31, 2001
854
JP
I can't for the life of me figure this out.
I have a table that lists events and using the MysQl Date format (ie 0000-00-00 ). This determines the date the event is happening on.

Im guessing its a mix of php and Mysql queries.

Even if today is x day of the week (ie tue,wed, fri) I want to be able to show the events of the Monday (if there are any). How can I construct a query to show events on Monday no matter what day of the week it is?

How can I show the events of the following Monday (, say if today is Wed)?

I know in php you can use:
$mon = mktime(0,0,0,date("m"),(date("d")-(date("w")-1)),date("Y"));
$mon_db = date("Y-m-d", $mon);

To determine the monday of the current week. How can I incoporate this into a mysql query? Also modify it to find the next Monday's events?
 
You could do it all in MySQL.

Explanation:
No matter what date it is, there was a Monday within the last 6 days. Right?

The MySQL functions DAYNAME(date) and TO_DAYS can help here:

SELECT * FROM table WHERE (DAYNAME(date)='Monday' AND TO_DAYS(NOW())- TO_DAYS(date)<=6) OR date = NOW()

There are many ways to do this. Hope the suggestion helps.

sleipnir214 has a good FAQ about date difference processing:
FAQ434-3493
 
Kay that works a bit, but I dont want it to show any events for any other Monday save for the one in the current week. How can I modify it so that it only shows that current weeks' Monday events and no other Monday?
 
Oopsie, nevermind. just switched around the Todays and (now) around and got it to work! thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top