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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

i would suggest using my query if you wish to grab ALL events in the next 7 days (not including today), rather than just the 7 events that are the farthest in the future...

 

Yup indeed. I'm going to give it a shot, stay tuned^^

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

@ 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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.