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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show the for the next 7 days.

Status
Not open for further replies.

WizyWyg

Technical User
Jan 31, 2001
854
JP
Hi all,

(Working with PHP and MySQL)

I have table "events" that list events by the day they happen.

How can I have it show only those events that are going to happen in the next 7 days from "now"?

Currently i have the following code:

SELECT * FROM events WHERE TO_DAYS(eventdate) - TO_DAYS(now()) <= 7 AND eventscat_id=1;

But it will show events that happened before now() as well.

I guess I need something in the where clause to not include anything that is <= 0 when the where clause subtracts now() from the eventdate.

Any ideas?
 
$future_date (?) dont have a variable/function for that and I wanted to work with what i have:

So, this works:

SELECT * FROM events WHERE eventdate >= now() AND eventdate <= now() + INTERVAL 7 DAY AND eventscat_id=3
 
This is the correct answer if the field type is date.
Careful with datetime and timestamp, as events that are sheduled for 5 mins will not be displayed.

Had this problem with my events system, I held 2 dates/times: start and end. They had to include date and time cos they could span several days. So had to create a constant in the PHP code &quot;THIS_MORNING&quot; and use that in the queries.

(P.S. use of timestamp is not advised unless for things such as last updated)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top