Next Birthday in Coda
Below an easy to follow but nevertheless wrong solution to get the next birthday.
As you see, I make again use of the base function
Date() as I did in my previous blog on dates, it avoids complications.
Although all looks fine, the provided code snippet does not deal with one exception: the leap year as you see below.
The year 2024 is a leap year and thus the outcome should be Feb 29, 2024. Instead it moved the year by one based on the birthday this year which is indeed March 01, 2023. Coda moves the date with one, because Feb 29 does not exist in 2023. When we add one year to this year, the outcome is both logical and mistaken.
What is a leap year?
A short intermezzo on the logic of leap years. In technical terms the year should be divisible by 4 or 400 but not by 100. In Coda terms:
),"Leap Year", "NOT a Leap Year")
The same outcome with another way of writing (syntax). My guideline is that code should be easy to read and thus be understood. Only when we can read out loud what is happening, we are on to something. In a next blog I explore in more detail the meaning of a lower floor.
Although 29 feb can only exist in a leap year, the question is, do we need the leap year logic? The good news is, we don’t and that is because what I wrote earlier. In the Coda formula language the date is moved ahead by one when the date looked at, is not present. We take advantage of that behavior and shorten our formula using a simple solution.
The simple solution
The final solution is actually rather simple. We generate the birthday as
Date() and compare it with the date of today. Crucial is the > operator.
No complexity with leap years. It is a short and elegant solution that keeps the base logic intact and does not work with unnecessary assumptions. It also works with EU formatted dates.
Below how to get the age:
Edit, Oct 27 , 2023
I added the blog I posted related to
Sign() permitting a compacter logic without
On this page you see the logic in action:
My name is Christiaan and I support SMB with calculations (budgets and — Human Resource — planning) and I prefer using Coda to get the job done. More about me below ⤵️
I've been an active Coda maker since early 2020. I am an expert at blending structured and unstructured data to solve…
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.
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.