Jump to content

[SOLVED] Displaying events in the next 7 days


Anzeo

Recommended Posts

Hi all,

 

 

 

In my current project I have made a simple calendar (actually a list of events that are stored in a db) and now I'd like to add a smaller list to my sidebar which displays only the events that occur in the next 7 days.

 

So basicly, I want to write a query which returns only the events in the next 7 days (not including this day).

 

Can anyone help me out with this? Any help greatly appreciated!

 

Thanks in advance,

Anzeo

you can use DATE_ADD() to figure out the dates one and seven days ahead from now, in combination with between:

 

SELECT stuff FROM table WHERE eventDate BETWEEN DATE_ADD(eventDate, INTERVAL 1 DAY) AND DATE_ADD(eventDate, INTERVAL 7 DAY)

Wouldn't my query do exactly what he is asking? It would even include an event on the same day, but after the time (if it has a time). It wouldn't be the 7 events that are the farthest in the future, it would simply return the 7 that are closest to the current date starting after it. Am I wrong?

@ Lemmin: You're coorect, but I want all events of the next 7 days not just the next 7 events ^^

 

@Akitchin:

you can use DATE_ADD() to figure out the dates one and seven days ahead from now, in combination with between:

 

SELECT stuff FROM table WHERE eventDate BETWEEN DATE_ADD([color=red]eventDate[/color], INTERVAL 1 DAY) AND DATE_ADD([color=red]eventDate[/color], INTERVAL 7 DAY)

 

Shoudn't these be this day date in stead of the event date?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.