Jump to content

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

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.