Forum Moderators: coopster
$query_calendar = "SELECT id, event, body, city, state, country,
DATE_FORMAT(date_start, '%Y%m%d') AS Fdate_start,
DATE_FORMAT(date_end, '%Y%m%d') AS Fdate_end
FROM calendar
WHERE date_start >= '2010-01-01'
AND type='event'
ORDER BY date_start";
$result_calendar = mysql_query($query_calendar)
or die ("Couldn't execute Calendar query.");
?>
BEGIN:VCALENDAR
PRODID:MyNameHere
X-WR-CALNAME:MyNameHere
X-WR-CALDESC:MyNameHere
VERSION:2.0
CALSCALE:GREGORIAN
<?php
while ($row_calendar = mysql_fetch_array($result_calendar))
{
extract($row_calendar);
// here we add one day to the end date because DTEND is exclusive
// meaning it considers the event ends at DTEND 00h00m00s
// not at DTEND 23h59m59s
// otherwise events will show as ending one day earlier in iCal
$tomorrow = strtotime('+1 day', strtotime($Fdate_end));
$Fdtend = date('Ymd', $tomorrow);
$h_event = html_entity_decode($event, ENT_QUOTES, "UTF-8");
$h_city = html_entity_decode($city, ENT_QUOTES, "UTF-8");
$h_country = html_entity_decode($country, ENT_QUOTES, "UTF-8");
?>
BEGIN:VEVENT<?php echo "\n"; ?>
SUMMARY:<?php echo $h_event; ?>
<?php echo "\n"; ?>DTSTART:<?php echo $Fdate_start; ?>
<?php echo "\n"; ?>DTEND:<?php echo $Fdtend; ?>
<?php echo "\n"; ?>LOCATION:<?php echo $h_city; if($state) { echo ", ".$state; } echo " - ".$h_country; ?>
<?php echo "\n"; ?>UID:<?php echo $id; ?>
<?php echo "\n"; ?>
URL:http://www.MyNameHere.com/events/<?php echo $id; ?>
<?php echo "\n"; ?>END:VEVENT
<?php
}
?>
END:VCALENDAR
//If I'm right, won't need the next two lines:
//$tomorrow = strtotime('+1 day', strtotime($Fdate_end));
//$Fdtend = date('Ymd', $tomorrow);
//this is presuming that your $Fdate_end is only the y-m-d date
//such as 20100505, without the time after it, add it on:
$Fdtend = $Fdate_end.'T235959Z'; //setting DTEND to the end of the given day, may help?