Three spellings of one day
A bakery list holds the dates 02/03/2026, 2 March 2026 and 2026-03-02. They are one day, written three ways.
A computer sees three different pieces of text. Before any analysis, the dates must be changed into one type and one format.
Key words
| Word | What it means | Example |
|---|---|---|
| Convert | To change data from one type to another. | Text "12" to the number 12 |
| Format | The way a value is written down. | Year, then month, then day |
| Type conversion | Changing the kind of a value in code. | int("12") |
| Parse | To read text and pull out its parts in a form a program can use. | Split a date at each slash |
| Currency | A money value, such as pounds and pence. | £12.50 |
| Requirement | What the analysis must achieve. | Total sales by day |
| ISO date | A date written year-month-day, which sorts correctly as text. | 2026-03-02 |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can change money, dates and yes or no values into one consistent type, and check the result.
Starter: what you already know
Have a go
Starter: what you already know
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Worked example: three messy values
| Raw value | Problem | Fixed value |
|---|---|---|
| £12.50 | A pound sign makes it text | 1250 pence, a whole number |
| 02/03/2026 | Day first, in text | 2026-03-02 |
| Y | A letter, not true or false | true |
| Sam | Extra spaces | Sam |
The cells students fill in are left blank in this preview.
Try it: convert in DuckDB
select cast(price as decimal(8,2)) as price,
strptime(day, '%d/%m/%Y')::date as day,
paid = 'Y' as paid
from raw;
-- Try it: add price * 2 as double_price to the list.Try it: convert in Python
text = "£12.50"
clean = text.replace("£", "")
parts = clean.split(".")
pence = int(parts[0]) * 100 + int(parts[1])
print(pence, type(pence))
# Why whole pence? Whole numbers add up exactly. Decimals can drift.
# Try it: change the price to "£0.99" and press Run.