๐ Format Conversion ยท 7 min read
CSV to iCal: Turn a Spreadsheet of Dates Into a Calendar File
An .ics file is not a converted spreadsheet. It is a small text document defined by RFC 5545, and a calendar either fits those rules or it does not import. Five lines of skeleton carry a working event; the difficulty is in four rules that fail silently: line endings, the date format, escaped punctuation, and a unique identifier per event.
If you have a list of dates in a CSV and want them in Google Calendar, Apple Calendar or Outlook, you have two routes. Import the CSV into a calendar that reads CSV, which almost none of them do, or write the .ics yourself. The second route is about twenty lines of Python and produces a file that works everywhere.
The Smallest Valid Calendar
This whole block is a complete, importable file with one event:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//NoCodeCSV//CSV to iCal//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:20260315-0930-site-visit@example.com
DTSTAMP:20260301T120000Z
DTSTART:20260315T093000Z
DTEND:20260315T110000Z
SUMMARY:Site visit - Bristol depot
LOCATION:Unit 4, Avonmouth
END:VEVENT
END:VCALENDARFour properties are non-negotiable. VERSION:2.0 because version 1 files are treated as something else entirely. PRODID because it identifies what wrote the file, and some clients refuse a calendar without it. UID because that string is how a calendar recognises an event it has seen before. DTSTAMP because it records when the event object was created.
The rest is optional, which is worth knowing when a file imports but looks bare: a SUMMARY missing means an untitled block on the calendar, not an error.
Line Endings Are Part of the Format
RFC 5545 requires each content line to end with CRLF, the carriage return and line feed pair. Most editors on macOS and Linux write LF only. Many importers tolerate LF, which is exactly why this problem is hard to learn: a file built on a Mac works locally and fails on a client, or the reverse.
Writing with Python's csv-free route makes it explicit: open the file with newline="" and join lines with "\\r\\n". If you are hand-editing, check the bytes rather than trusting the editor. A file with no carriage returns is worth rebuilding before you spend an hour on the other three rules.
DTSTART: The Date Format Nobody Guesses
Dates inside an .ics are basic format, meaning no separators at all. Compare:
| What you have | What goes in the file | Property |
|---|---|---|
2026-03-15 | 20260315 | DTSTART;VALUE=DATE: |
2026-03-15 09:30 | 20260315T093000 | Floating local time |
2026-03-15 09:30 UTC | 20260315T093000Z | The trailing Z means UTC |
2026-03-15 09:30 +01:00 | 20260315T083000Z | Convert, then use Z |
Two choices follow from that table. A timestamp ending in Z is absolute: every client shows it at the correct local hour. A timestamp with no Z is floating, meaning 9:30 stays 9:30 no matter where the calendar is opened. A TZID parameter would give a named zone, but it requires a VTIMEZONE block in the file, and getting those rules wrong is a longer detour than converting your times to UTC once.
For a spreadsheet full of local times and a worldwide audience, floating is usually the better answer. For booking systems and anything with a deadline, use UTC.
All-Day Events and the Exclusive End Date
An all-day event uses VALUE=DATE, and its DTEND is exclusive. One day, 15 March:
DTSTART;VALUE=DATE:20260315
DTEND;VALUE=DATE:20260316Reusing 20260315 for both produces a zero-length event. Some clients show it as a one-day banner, others drop it, and a batch imported that way looks like a file with missing rows. Adding one day to the end is the whole fix, and it is the single mistake that comes up most in calendar imports.
Escaping: Commas, Semicolons, Backslashes
Inside a TEXT value such as SUMMARY, LOCATION or DESCRIPTION, three characters are structural and must be escaped with a backslash: the comma, the semicolon, and the backslash itself. A line break becomes a literal \\n.
A title like Review, final written unescaped is truncated by strict parsers at the comma. A location like Hall B; gate 3 is worse, because the semicolon is the separator for structured values and the client may try to read what follows as another component.
SUMMARY:Review\, final
LOCATION:Hall B\; gate 3
DESCRIPTION:Agenda:\n1. Budget\n2. ScheduleEscaping is cheap when you write it in code and easy to forget when you build the file in a spreadsheet with string concatenation. If you are assembling lines in Excel, the escaping step belongs in a helper column, not in your head.
The Script
Standard library, CRLF endings, UTC timestamps, exclusive end dates, and escaping handled in one place:
import csv, hashlib
from datetime import datetime, timedelta
def esc(s):
return (s.replace("\\", "\\\\").replace(";", "\\;")
.replace(",", "\\,").replace("\n", "\\n"))
def dt(value):
"""'2026-03-15 09:30' -> '20260315T093000Z' (input treated as UTC)"""
return datetime.fromisoformat(value.strip()).strftime("%Y%m%dT%H%M%SZ")
def day(value):
return datetime.fromisoformat(value.strip()).strftime("%Y%m%d")
events = []
with open("events.csv", newline="", encoding="utf-8-sig") as f:
for row in csv.DictReader(f):
uid = hashlib.sha1((row["title"] + row["start"]).encode()).hexdigest()[:16]
if row.get("all_day", "").strip().lower() in ("1", "yes", "true"):
start = "DTSTART;VALUE=DATE:" + day(row["start"])
end = "DTEND;VALUE=DATE:" + day(
(datetime.fromisoformat(row["start"].strip())
+ timedelta(days=1)).isoformat())
else:
start = "DTSTART:" + dt(row["start"])
end = "DTEND:" + dt(row["end"])
events += [
"BEGIN:VEVENT",
"UID:" + uid + "@nocodecsv.com",
"DTSTAMP:20260301T000000Z",
start, end,
"SUMMARY:" + esc(row["title"]),
"END:VEVENT",
]
ics = ["BEGIN:VCALENDAR", "VERSION:2.0",
"PRODID:-//NoCodeCSV//CSV to iCal//EN"] + events + ["END:VCALENDAR"]
open("events.ics", "w", newline="", encoding="utf-8").write("\r\n".join(ics) + "\r\n")The dt helper treats your column as UTC, which is the assumption to make explicit rather than accidental. If the times are local, convert them before they reach this function.
The UID is derived from the title and start time, which gives the same event the same identifier on every run. That matters more than it looks. Re-import a file with fresh UIDs and the calendar gains duplicates; re-import one with stable UIDs and the calendar updates the existing events.
Test With Three Events, Not Three Hundred
Build a file with three events: one all-day, one with a comma in the title, one that crosses midnight. Import it, then check the calendar for four things. The all-day event occupies exactly one day. The title shows its comma. The overnight event ends on the next date rather than at 00:00. And the count of imported events matches the count in your CSV.
If the import returns nothing at all, suspect line endings first and UIDs second. If it returns the events with empty titles, the problem is on the SUMMARY line, usually an unescaped character that ended the value early.
Spreadsheet side problems tend to arrive before the calendar does: dates reformatted on save, leading zeros lost from times, blank rows from a trailing newline. The date format that changes on save and blank row removal cover both. If you want a reference file to test against, the CSV example set has quoted fields and mixed types.
Frequently Asked Questions
What is an iCal file, in one sentence?
A plain-text calendar defined by RFC 5545: a VCALENDAR block holding one or more VEVENT blocks, where each line is a property name, a colon and a value. The extension is usually .ics.
Why do my events disappear on import?
Missing or duplicated UID, a DTSTART format that does not match its declared value type, LF instead of CRLF line endings, or a file that is still comma separated underneath the .ics name. Strict parsers import zero events and report nothing.
How should dates be written?
YYYYMMDD for a date and YYYYMMDDTHHMMSS for a local time, with a trailing Z for UTC. No hyphens, no colons.
Why is the all-day end date one day later?
DTEND is exclusive, so a single day on 15 March needs an end of 20260316. Reusing the same date gives a zero-length event.
Do commas in titles need escaping?
Yes, along with semicolons and backslashes. A line break inside a description is written as \\n. Unescaped commas truncate the value.
How many events fit in one file?
The format has no limit; importers do. Past a few thousand events, split by month or category and import the parts, each with its own wrapper and its own UIDs.
Fix the Dates Before the Calendar
Half of every calendar import failure starts in the spreadsheet: a date column stored as text, a time that lost its leading zero. Check both in one pass.
Related reading
Format Conversion โ other guides that pair well with this one.
- Transpose a CSV File
- Convert Text to CSV
- Pandas read_csv and Too Many Columns: Missing or Failing
- Why Is My CSV a Text File? Because It Is
Browse all guides in the NoCodeCSV blog.