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 Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/ 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) Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326046 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 Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326048 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" Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326051 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... Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326053 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^^ Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326062 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? Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326075 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? Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326083 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. Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326089 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Oh, I see, sorry about that. Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326096 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! Link to comment https://forums.phpfreaks.com/topic/65291-solved-displaying-events-in-the-next-7-days/#findComment-326115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.