my ics file file does not show the correct time in outlook

by Rene Fallesen   Last Updated August 01, 2020 11:26 AM - source

my ics file retrieves time and date from my mysql database - it also works fine if I make a print_r but as soon as I insert the ics file in outlook it does not display it correctly anymore. it looks like it shows the time which is here and now - are there any who can help with and see where it goes wrong in my code

  <?php
    session_start();
    include 'db.php';
    // print_r($_SESSION);
    // exit;
    if(empty( $_SESSION['username']))
    {
      header('location: index.php');
      exit;
    }
    
    if(isset($_REQUEST["event_id"]))
    {
        $eid=$_REQUEST["event_id"];
        $query=mysqli_query($conn, "select * from student where id='$eid'");
    
        //$row=mysqli_fetch_array($query);
    
        //$etime = $row['etime'];
        //$start_time = str_replace(":","",$row['etime'])."00";
    
        //$start_time = $row['etime'];
        // print_r($start_time);
        // exit;
        //substr($row['etime'],0,2);
        //$start_time = str_replace(":","",$row['etime'])."00";
        
        // $start_time = $start_time - 1;
        // $start_time = $start_time."0000";
        //exit;
    
            //$start_date   = $row['edate'];
        //$start_time   = $row['etime'];
    //$start_date = str_replace("-","",$start_date);
    $ics_data = "BEGIN:VCALENDAR\n";
    $ics_data .= "VERSION:2.0\n";
    $ics_data .= "PRODID:PHP\n";
    $ics_data .= "METHOD:PUBLISH\n";
    $ics_data .= "X-WR-CALNAME:Schedule\n";
    
    # Change the timezone if needed
    $ics_data .= "X-WR-TIMEZONE:Asia/Kolkata\n";
    $ics_data .= "BEGIN:VTIMEZONE\n";
    $ics_data .= "TZID:Asia/Kolkata\n";
    $ics_data .= "BEGIN:DAYLIGHT\n";
    $ics_data .= "TZOFFSETFROM:-0500\n";
    $ics_data .= "TZOFFSETTO:-0400\n";
    $ics_data .= "DTSTART:1403086496\n";
    $ics_data .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n";
    $ics_data .= "TZNAME:EDT\n";
    $ics_data .= "END:DAYLIGHT\n";
    $ics_data .= "BEGIN:STANDARD\n";
    $ics_data .= "TZOFFSETFROM:-0400\n";
    $ics_data .= "TZOFFSETTO:-0500\n";
    $ics_data .= "DTSTART:1403086496\n";
    $ics_data .= "RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n";
    $ics_data .= "TZNAME:EST\n";
    $ics_data .= "END:STANDARD\n";
    $ics_data .= "END:VTIMEZONE\n";
    
    while ($event_details = mysqli_fetch_assoc($query)) {
    
    $id = $eid;
    $start_date =date("d-m-Y", strtotime($event_details['edate']));
    $start_time = $event_details['etime'];
    $end_date = date("d-m-Y", strtotime($event_details['edate']));
    $end_time = $event_details['etime'];
    $name = $event_details['title'];
    $location = 'UAE';
    $description = $event_details['felt'];
    
    # Replace HTML tags
    $search = array("/<br>/","/&amp;/","/&rarr;/","/&larr;/","/,/","/;/");
    $replace = array("\\n","&","-->","<--","\\,","\\;"); 
    
    $name = preg_replace($search, $replace, $name);
    $location = preg_replace($search, $replace, $location);
    $description = preg_replace($search, $replace, $description);
    
    # Change TimeZone if needed
    $ics_data .= "BEGIN:VEVENT\n";
    $ics_data .= "DTSTART;TZID=Asia/Kolkata:".$start_date."T".$start_time."\n";
    $ics_data .= "DTEND:" . $end_date . "T" . $end_time . "\n";
    $ics_data .= "DTSTAMP:" . date('d-m-Y') . "T" . date('H:i:s') . "Z\n";
    $ics_data .= "LOCATION:" . $location . "\n";
    $ics_data .= "DESCRIPTION:" . $description . "\n";
    $ics_data .= "SUMMARY:" . $name . "\n";
    $ics_data .= "UID:" . $id . "\n";
    $ics_data .= "SEQUENCE:0\n";
    $ics_data .= "END:VEVENT\n";
    }
    
    $ics_data .= "END:VCALENDAR\n";
    
    # Download the File
    $filename = "event_calendar.ics";
    header("Content-type:text/calendar");
    header("Content-Disposition: attachment; filename=$filename");
    echo $ics_data;
    exit;
    }
    ?>

Tags : php icalendar


Related Questions


how to create iCal feed .net

Updated April 20, 2015 23:11 PM

Siri showing incorrect time for iCal file

Updated September 17, 2018 22:26 PM

"Unmerging" merged google calendar data with jq

Updated July 03, 2017 16:26 PM