title: Create .ics file dynamically
body: <p>I made a website for a client where they can post events. Instead of manually creating .ics files from iCal for every event and uploading it, I though it would be better to pull it out of the database and automatically create a .ics file automatically with PHP.</p>
  
  <p>I can pull information from the database (no problem), but when converting it to a time stamp for the calendar file it a tough one. Here's what I store in the database:</p>
  
  <pre><code>Month: 05
  Day: 02
  Year: 2011
  Time: 11:30am - 1:30pm
  </code></pre>
  
  <p>Here's the code to create my .ics files:</p>
  
  <pre><code>//This is the most important coding.
  header("Content-Type: text/Calendar");
  header("Content-Disposition: inline; filename=adamhouston_$id.ics");
  
  echo "BEGIN:VCALENDAR\n";
  echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
  echo "VERSION:2.0\n";
  echo "METHOD:PUBLISH\n";
  echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
  echo "BEGIN:VEVENT\n";
  echo "CLASS:PUBLIC\n";
  echo "CREATED:20091109T101015Z\n";
  
  echo "DESCRIPTION:Speaker: $event_query_row[speaker_name]\\n\\nTopic: $event_query_row[speaker_topic]\n";
  echo "DTEND:20100208T040000Z\n";
  echo "DTSTAMP:20100109T093305Z\n";
  echo "DTSTART:20100208T003000Z\n";
  echo "LAST-MODIFIED:20091109T101015Z\n";
  echo "LOCATION:$event_query_row[location]\n";
  echo "PRIORITY:5\n";
  echo "SEQUENCE:0\n";
  echo "SUMMARY;LANGUAGE=en-us:ADAM-Houston Event\n";
  echo "TRANSP:OPAQUE\n";
  echo "UID:040000008200E00074C5B7101A82E008000000008062306C6261CA01000000000000000\n";
  echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
  echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
  echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
  echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
  echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
  echo "X-MS-OLK-CONFTYPE:0\n";
  //Here is to set the reminder for the event.
  echo "BEGIN:VALARM\n";
  echo "TRIGGER:-PT1440M\n";
  echo "ACTION:DISPLAY\n";
  echo "DESCRIPTION:Reminder\n";
  echo "END:VALARM\n";
  echo "END:VEVENT\n";
  echo "END:VCALENDAR\n";
  </code></pre>
  
  <p>Now how do I convert the data in my database to a correct time/date stamp?</p>