Jump to content

Using Date functions in events calendar


slaterino

Recommended Posts

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

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

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.