Chapter 7: dates, typed
Chapter 7 does arithmetic on dates: a start date, a notice period of one month and fifteen days, the due date they give, and the span between. The values are literals you type; the IDE writes the program's shell. To play it in the IDE: Help > Lessons > Getting Started with EK9…, or ek9 -ide -lesson book-deadline.
What you'll build
The lesson builds this program from a file holding only its module line - the finished file, as the book prints it.
#!ek9 defines module book.dates defines program Deadline() stdout <- Stdout() enGB <- Locale("en_GB") start <- 2026-01-15 notice <- P1M15D due <- start + notice stdout.println(`Start: ${enGB.mediumFormat(start)}`) stdout.println(`Due: ${enGB.mediumFormat(due)}`) span <- due - start stdout.println(`Notice period is ${span}`) stdout.println(`Due falls on day-of-week ${due.dayOfWeek()}`)
Step 1: The program's shell
Choose Code > New Construct > Program…
Deadline is the program's name. Type it and choose Preview.
The preview shows Deadline about to be written. Choose Apply.
The tool leaves no blank line before the program: select the Deadline() line and, above it, type the one the book opens with. Saves when typed.
Step 2: The body, typed
Select the stub, from ready <- true down to its //AI line, and type the body exactly as the chapter shows it. Saves when typed.
Step 3: Run it
Choose Run > Run Program…
The project's only program is already chosen. Choose Run.
Start: 15 Jan 2026, Due: 2 Mar 2026, Notice period is P1M15D, Due falls on day-of-week 1. Choose Close.
The result
Deadline.ek9 now reads exactly as chapter 7 of Getting Started with EK9 shows it: a Date plus a Duration gives a Date, and a Date minus a Date gives a Duration - all formatted for en_GB.
Where this lesson comes from
- For AI assistants - the MCP tool
ek9_add_program.
In the EK9 reference: EK9 Basics








