Creating A Function In Coda

I want to make a Coda function that returns the gap years from a list of dates. The numbers of dates in a list can vary.

For example :

July 1, 2016, September 1, 2010, July 1, 2022

The gap years between these dates are 6 years.

Another Example:

Sept 1, 2010, July 1, 2012, Sept 1, 2014, July 1, 2016

The gap years between these dates is 2. How will I make a function in Coda to identify the gap years? Thanks!

Will it always be the same gap? No matter how many dates per calculation?

Or would would you expect to happen if you have the dates Xx.2014, xx.2018 xx.2019?

And other question:
Do the actual dates matter? Or just the year?

Like what would you expect if there is 1. sept 2018, 30. august 2019. is this 0 or 1 year?
According to example two it would be 1, right?

In case there is always the same gap and it doesn’t matter what day it is (which is the simplest), then you could just do this:

The formula gets the year of date #2 and substracts it from the year of date #1. To make sure they are in order (in your exmample 1 they are not) and you get a positive value, I’ve added a sort() inbetween.

1 Like

Thanks! Yes some list of dates doesn’t have the same gap. If that would be the case , the gap will be the minimum gap.

If the year is not the same, we would just have to subtract its years.

If the years are the same, but not the months and date, I need to classify wther the gap is monthly, quarterly or bi-annual.

Is there any way we can loop the subtraction to cater three or more dates in a list?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.