Re base: Oct 14 1939 birthday - how to display as occurring on Wed (this year) rather than Fri (1939)

My frontmatter:

calendar: 1939-10-14
calendartext: "🎈 mom's birthday"

What I’m trying to do

My Calendar Base has a view for each month. When I go to October, for example, I want all my calendar dates to display as ddd MMM DD, so “Wed Oct 14” via a formula.

The problem is that the weekday is assigned by the calendar.year, so Oct 14 displays as “Sat Oct 14” rather than “Wed Oct 14” (in 1939 Oct 14 was on a Sat).

I need to somehow use today’s year and today’s days of the week, with the calendar’s month and date. But, as I found out, you can’t just connect the two.

Things I have tried

I’ve tried a bunch of combinations using today().year with calendar months and days, but the combo always seems to require turning today().year into a string, to the use the "+ " to build up the new ‘fake’ date. Problem is I still can’t get the days of the week out of that, or at least I don’t know how.

today().year.toString() + " " + calendar.format("ddd MMM DD")

I even tried wrapping this up with another date( ).format("ddd MMM DD"), you know, to create a date out of all the strings, but that didn’t work either.

I’m wondering if I could just use some form of “convert date to this year”.

Happy birthday to mom!

There’s no direct function that returns this year’s anniversary date of another date.

You can put together the string inside of date(). Two examples:

date([today().year, calendar.toString().split("-").slice(-2)].flat().join("-"))
date(today().year + "-" + ("0" + calendar.month).slice(-2) + "-" + ("0" + calendar.day).slice(-2))

Another way is to calculate the strict year difference and add that to the original date:

calendar + duration(today().year - calendar.year + "y")

Then you can use .format() at the end.

For the third one, be sure to gather the date in parentheses before doing operations on it:

(calendar + duration(today().year - calendar.year + "y")).format("ddd MMM DD")

Note:

Each of those returns the anniversary this year, which isn’t necessarily the upcoming anniversary. Could create confusion on, for example, Thu Dec 31st when the base shows your friend’s Thu Jan 1st birthday.

And in non-leap years, leap days will turn into Mar 1st.

You would need additional logic to handle those.

This was the first use case I wanted to solve via Bases.

At least now I know there’s no definitive/dedicated solution.

These seem to work:

---
calendartext: "🎈 mom's birthday"
calendar: 1939-10-14
---

## F1 > ==🔴NEXT Birthday==

~~~
if(date(now().format("YYYY") + "-" + date(calendar).format("MM-DD")) >= now(), date(now().format("YYYY") + "-" + date(calendar).format("MM-DD")).format("ddd, DD MMM YYYY"), date((now().year + 1) + "-" + date(calendar).format("MM-DD")).format("ddd, DD MMM YYYY"))
~~~

## F2 > This Year

~~~
(calendar + duration(today().year - calendar.year + "y")).format("ddd, DD MMM YYYY")
~~~

## F3 > This Year

~~~
date(today().year + "-" + calendar.format("MM-DD")).format("ddd, MMM DD YYYY")
~~~

~~~base
formulas:
  F1: if(date(now().format("YYYY") + "-" + date(calendar).format("MM-DD")) >= now(), date(now().format("YYYY") + "-" + date(calendar).format("MM-DD")).format("ddd, DD MMM YYYY"), date((now().year + 1) + "-" + date(calendar).format("MM-DD")).format("ddd, DD MMM YYYY"))
  F2: (calendar + duration(today().year - calendar.year + "y")).format("ddd, DD MMM YYYY")
  F3: date(today().year + "-" + calendar.format("MM-DD")).format("ddd, DD MMM YYYY")
views:
  - type: table
    name: View
    filters:
      and:
        - "!calendar.isEmpty()"
    order:
      - calendartext
      - formula.F1
      - formula.F2
      - formula.F3
    columnSize:
      note.calendartext: 182
      formula.F1: 182
      formula.F2: 182
      formula.F3: 182
~~~
```

If you’re interested, you can whittle all of that down to:

```base
formulas:
  thisYear: date(today().year + "-" + calendar.format("MM-DD"))
  nextBirthday: if(formula.thisYear >= today(), formula.thisYear, formula.thisYear + "1y").format("ddd MMM DD")
views:
  - type: table
    name: View
    filters:
      and:
        - calendar
    order:
      - file
      - formula.nextBirthday

```

This is indeed simple and does the trick.
I also learned that we can refer to a formula (`formula.thisYear’), so that’s cool.

Thank you for taking the time to help me out. I appreciate it.

Thanks for taking the time to help me out.

I’m learning now that it is better to treat the base formulas like real programming, where every function is small, singular, and separate, and then we can bring them together if need be. I tend to try to put everything in one large formula and of course I get lost half the time.

I’m assuming that more but smaller formulas like this are easier on bases (re compiling, and speed).

I’ve copied your method into my “bases - how to” file, but I think I’m going to go with dawni’s simpler method below. Having said that, I’m this close to complicating everything by including monthly items and todo stuff with due dates into the same views, so yeah, multiple smaller functions are definitely going to come in handy for that project!