I am trying to add events to google,outlook and ical calendar. Adding event to google calendar is working just fine but for outlook and ical there is some issue in time. When i add start time as 1:00 pm and end time as 12:00 am for the same date ical is generating end time as 12:00 am and end time as 1:00 pm. I am generating ical as follows. I don't know what am i doing wrong ? Any help/suggestions is appreciated.
$startDate = $_GET['startDate'];
$startTime = $_GET['startTime'];
$startDateTime = $startDate . ' ' . $startTime; //2020-10-08 13:00:00
$endDate = $_GET['endDate'];
$endTime = $_GET['endTime'];
$endDateTime = $endDate . ' ' . $endTime; //2020-10-08 00:00:00
$subject = $_GET['subject'];
$desc = $_GET['desc'];
$location = $_GET['location'];
$filename = $subject . '.ics';
$format = 'Y-m-d H:i:s';
$icalformat = 'Ymd\THis';
$startDateTime = DateTime::createFromFormat($format, $startDateTime);
$startDateTime = $startDateTime->format( $icalformat );
$endDateTime = DateTime::createFromFormat( $format, $endDateTime );
$endDateTime = $endDateTime->format( $icalformat );
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5( uniqid( mt_rand(), true ) ) . "example.com
DTSTAMP:" . gmdate('Ymd') . 'T' . gmdate( 'His' ) . "
DTSTART:" . $startDateTime . "
DTEND:" . $endDateTime . "
LOCATION:" . $location . "
SUMMARY:" . $subject . "
DESCRIPTION:" . $desc . "
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header( 'Content-type: text/calendar; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=' . $filename );
echo $ical;
exit;
How can the end time be earlier than the start time? Should it not be the midnight of the next day? 2020-10-09 00:00:00.