slaterino Posted September 9, 2008 Share Posted September 9, 2008 Hi, I have created a simple events calendar list. However, I want the list to only show events for 12 months at a time, i.e. to only display events between today's date and the date in 12 months time. Does anyone know how I would go about conding this? The current code for my page is: <?php include 'library/config.php'; include 'library/opendb.php'; $query = "SELECT society, venue, dates, contactname, contactadd, contacttel, contactemail FROM showdates ORDER BY dates ASC"; $result = mysql_query($query); while(list($society, $venue, $dates, $contactname, $contactadd, $contacttel, $contactemail)= mysql_fetch_row($result)) { list($year,$month,$day)=split("-",$dates); $dates=date("j M Y",mktime(0,0,0,$month,$day,$year)); echo ($dates?"<b>$dates</b> - ":"").($venue?"<b>$venue</b><br />":"").($society?"<b>$society</b><br />":"").($contactname?"Contact: $contactname<br />":"").($contactadd?"Address: $contactadd<br />":"").($contacttel?"Tel: $contacttel<br />":"").($contactemail?"E-mail: <a href=mailto:$contactemail\">$contactemail</a>":"").("<br /><br />"); } include 'library/closedb.php'; ?> Thanks Russ Link to comment https://forums.phpfreaks.com/topic/123527-using-date-functions-in-events-calendar/ Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 In your query, you can do a WHERE with curdate and Interval +12 months. Link to comment https://forums.phpfreaks.com/topic/123527-using-date-functions-in-events-calendar/#findComment-637975 Share on other sites More sharing options...
Adam Posted September 9, 2008 Share Posted September 9, 2008 yeah, save the date field in your database as a "date" format .. and then use: mysql_query("SELECT * FROM yourTable WHERE dateField BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 365 DAY)"); ... that's the way i use anyway... EDIT: Not massively experienced here so could be used with like 12 MONTH instead of 365 DAY ?? Adam Link to comment https://forums.phpfreaks.com/topic/123527-using-date-functions-in-events-calendar/#findComment-637978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.