How to Coda your year dates?
Select your code wisely
I came across a post about how to create all dates of a year using a button. It intrigued me. First the proposed function:
I had to look twice before understanding what happened after I had read the intro:
Want to know a Coda super-trick? While making my Habit Tracker super template in @coda_hq
I needed a table with one row per day in 2023. Manually adding those rows would have been a nightmare Heres the formula I wrote to do it in a single button press #nocode #buildinpublic
It is about all dates in 2023. That confused me, why using EndOfMonth()
in combination with Today()
in the second part of the Sequence()
?
Inside the EndOfMonth()
we inject the date of today and because it is put in this context, the function automatically detects the month related to the date. In december we have month number 12. Once you add 12 as the monthOffset
in the function while living in december, you are moving 12 months ahead. This results in the last date of december 2023. The sequence starts on 01/01/2023 and moves day by day to the end. You have all the dates of 2023. So far so good.
This part of the function is misleading. Once you live in January 2023 it will output something else for logical reasons. See below (where I replaced Today with Jan 21, 2023:
Next I observed two times ForEach()
. As regular reader you know that Foreach evaluates each item in the list, meaning it picks up the item and does something with it. In our case the items are the dates generated via Sequence()
and the author asks first to turn each item into a date of the type 12/20/2022. That is not necessary, the dates are already there, but not formatted as this kind of date, formatted as numbers. The formatting is better applied in the table than in the button. The table simply provides more options once the column is formatted as a date column. Anyway, it is an option to print the numbers as dates, nothing particular wrong with that aside of the fact that you do not need ForEach twice. You could have done it as Coda proposed it: chained to the currentvalue
.
The Coda solution shows an important basic: generate a list (here they reference a date picker I wrote about here), evaluate it each item and then add each item as a new row. The date picker avoids your define the wrong end date and is a great option once you are not used to the USA date formatting. However the syntax of the function is not very Coda ‘sh, it feels like an Excel function with all these brackets. The formula lacks simplicity while reading. It feels like a missed opportunity when it comes to show the power of the Coda Formula Language.
My suggestions
The easiest alternative to generate all dates per given year is to see that the start and end date of any given year only differ for one element: the year. The January always starts on the first and December has 31 days.
This is rather simple and for those who forget to define the destination column as a date, you can chain ToDate()
to CurrentValue
as in the Coda example.
Once you want to have all dates between today and today a year from now, you do something else:
It seems that some people are better in selling products than using them and that some Coda employees cannot get rid of old habits. The solution is not hard at all, there is no magic, it is all rather simple once you see that everything is a list and items in a list have properties. Below the examples.
I hope you enjoyed this article. If you have questions feel free to reach out. Though this article is for free, my work (including advice) won’t be, but there is always room for a chat to see what can be done. Besides you find my (for free) contributions to the Coda Community and on Twitter
My name is Christiaan and I support SMB with calculations (budgets and planning) and I prefer using Coda to get the job done.
Coda comes with a set of building blocks ー like pages for infinite depth, tables that talk to each other, and buttons that take action inside or outside your doc ーso anyone can make a doc as powerful as an app (source).
Not to forget: the Coda Community provides great insights for free once you add a sample doc.
If you enjoyed this read and would like to get more Coda related content, please consider a Medium membership. It is it only $5 a month, and you’ll have access to every article ever published on Medium. If you sign up using my referral link, I’ll earn a small commission.