Facebook Event exports take two

So a while ago I wrote a php script to make facebook event names appear properly on google calendar.
I’ve since noticed that all ‘full day’ events on facebook get exported as though they are on the previous day! Someone has written a page to do this, but the source code is not available and so it depends if you trust them with your events or not.

As such I updated my php script to do this date change too! Code below, but if you want to use it on my site:

Get the uid and the key from your events page on facebook by clicking the gear in the top right, and export events, then get the URL of ‘upcoming events’.

For adding this to google calendar use webcal:// instead of http://


// Facebook uses ZULU time for it's exports.

function inc_date($matches) {
        $date = new DateTime($matches[2]);
        $date->add(new DateInterval('P1D'));
        return "DT".$matches[1].":".$date->format('Ymd');
$ical = "https://www.facebook.com/ical/u.php?uid=".$_GET['uid']."&key=".$_GET['key'];

$pattern = "#DT(START|END):([0-9]{8})[\n\r]#";
$file = preg_replace_callback($pattern, "inc_date", $file);

header("Content-Type: text/Calendar");
// Give the file a name and force download
header("Content-Disposition: inline; filename=events.ics");

One Reply to “Facebook Event exports take two”

Leave a Reply

Your email address will not be published. Required fields are marked *

You\'re not a robot are you? *