Skip to content

Instantly share code, notes, and snippets.

@semifor
Last active July 19, 2024 15:01
Show Gist options
  • Save semifor/b1f6fa919c4639599831acd3e4735b45 to your computer and use it in GitHub Desktop.
Save semifor/b1f6fa919c4639599831acd3e4735b45 to your computer and use it in GitHub Desktop.
Selecting anniversary dates in a query given the original event date

Selecting anniversary dates in a query given the original event date

I wrote a dataview query to display upcoming birthdays and another for upcoming event anniversaries. Selecting anniversary dates within a range is an interesting problem.

  1. subtract event date from today to get the difference in years.
  2. Take the ceiling to get whole years.
  3. Add it to the event date to get the next anniversary that is on or after the current date.
  4. Test that date to see if it is in range.

Here's a snippet in dataview's query language.

​where date + dur((ceil((date(today) - date).years)) + "year")
    >= date(today)
​and date + dur((ceil((date(today) - date).years)) + "year")
	< date(today) + dur(30day)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment