
Recently I created my own ics calendar, I found many topics on google how to create it, but the difficult part was creating an all day event.
The DTSTART tag should only contain Ymd, no timestamp, only date. The DTEND tag can be deleted. I’ll show you my the necessary codes of my php file to create the ics format.
header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: inline; filename=calendar.ics'); echo "BEGIN:VCALENDAR\r\n"; echo "VERSION:2.0\r\n"; echo "NAME:My Calendar\r\n"; echo "X-WR-CALNAME: My Calendar\r\n"; echo "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; foreach ($events as $e) { echo "BEGIN:VEVENT\r\n"; echo "UID:" . md5(uniqid(mt_rand(), true)) . "\r\n"; echo "DTSTAMP:" . date('Ymd\THis\Z')."\r\n"; echo "DTSTART:" . date('Ymd', $e->starttime) . "\r\n"; //echo "DTEND:" . date('Ymd\THis\Z', $e->endtime) . "\r\n"; # hide for all day event echo "SUMMARY:" . $e->title ."\r\n"; echo "END:VEVENT\r\n"; }
Happy coding!