36 — Diary: writing it down with today's date
A diary needs when it was written. Typing the date by hand goes wrong and gets forgotten. The computer already knows it, so ask it.
A program that writes files does not run on the site.
Steps
Open the date tools. One line brings the words that ask about dates:
run it →use date latest show today show weekday show yearSomething like
2026-08-19,Wednesday,2026. The clock is UTC — with a different clock per country the same program would answer differently for different people.Put the date in a name so it can be used more than once:
run it →use date latest set stamp to today set day to weekday show stamp show dayPut the date, the weekday and the note into one line. It is the shape from guide 40:
run it →set stamp to "2026-08-19" set day to Wednesday set note to it rained a little set lines to an empty list append stamp to lines append day to lines append note to lines set row to lines joined by comma show row2026-08-19, Wednesday, it rained a little. A date typed by hand needs quotes —2026-08-19on its own reads as a sum with subtraction in it. Whattoday()hands you needs none.Save it, read it back, take the fields out:
run it →set row to "2026-08-19, Wednesday, it rained a little" write row to "diary.txt" read "diary.txt" into memo set fields to memo split by comma show the first of fields show the last of fieldsThe whole thing:
run it →use date latest set stamp to today set day to weekday set note to it rained a little set lines to an empty list append stamp to lines append day to lines append note to lines set row to lines joined by comma write row to "diary.txt" read "diary.txt" into memo show memo
Try it yourself
Add days_after(7) to write down what the date will be a week from now;
days_after(-1) is yesterday. Then ask for the note and it becomes a real
diary — except that it overwrites. Keeping entries means reading what is
there, adding to a list, and writing the whole thing back.
What you learned
- One line of
use date latestbringstoday(),weekday(),year()anddays_after(n). - Put a date in a name and use it as often as you like.
- Date, weekday and note joined by commas make a one-line record.
- The clock is UTC, so the program answers the same for everyone.