Anzeo Posted August 16, 2007 Share Posted August 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 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) Quote Link to comment Share on other sites More sharing options...
nathanmaxsonadil Posted August 16, 2007 Share Posted August 16, 2007 SELECT * FROM `events` ORDER BY `time` DESC LIMIT 7 Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 It has to be greater than the current date, though. "...WHERE Date > NOW() ORDER BY Date LIMIT 7" Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 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... Quote Link to comment Share on other sites More sharing options...
Anzeo Posted August 16, 2007 Author Share Posted August 16, 2007 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^^ Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 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? Quote Link to comment Share on other sites More sharing options...
Anzeo Posted August 16, 2007 Author Share Posted August 16, 2007 @ 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? Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 @anzeo: you're right, it should be NOW() rather than eventDate in those DATE_ADD() statements. @lemmin: you're right, i thought you were ordering by the Date in descending order. my mistake. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Oh, I see, sorry about that. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted August 16, 2007 Author Share Posted August 16, 2007 It's working! Thanks alot for the help and the time guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.